For a long-running service managed by systemd, add Restart=on-failure under [Service], set a sensible delay with RestartSec=, then reload systemd and restart the unit. A typical drop-in is:
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
# /etc/systemd/system/example.service.d/override.conf
[Service]
Restart=on-failure
RestartSec=5s
This restarts the service after an error, signal termination, operation timeout, or watchdog timeout, but not after an administrator deliberately runs systemctl stop. Use a drop-in rather than editing a vendor unit file so package upgrades do not erase your change.
As an Amazon Associate I earn from qualifying purchases.
Free tools Windows power users keep installed
One-click scans. No signup required.
The quickest reliable setup
Replace example.service with the real unit name. The following procedure creates a package-safe override, applies it, and checks the result.
-
Create the drop-in directory:
sudo mkdir -p /etc/systemd/system/example.service.d -
Open an override file:
sudo nano /etc/systemd/system/example.service.d/override.confPut this in the file:
[Service] Restart=on-failure RestartSec=5sRestartSec=5sis an example. Choose a delay that gives the process time to release resources and avoids an immediate crash loop.#1 Best Overall
SaleTOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
-
Tell systemd to reread unit configuration:
sudo systemctl daemon-reload -
Restart the service so the new policy is active:
sudo systemctl restart example.service -
Inspect its current state and recent boot logs:
systemctl status example.service journalctl -u example.service -b
If the unit is currently disabled, automatic restart still works when the service is started by another unit or manually; enabling it for boot startup is a separate decision:
sudo systemctl enable example.service
Do not confuse “enabled” (started as part of boot targets) with “restart on failure” (what systemd does after the process exits or is terminated abnormally).
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsWhat systemd considers a failure
The systemd project recommends Restart=on-failure for long-running services because it attempts automatic recovery from errors. The policy covers several failure paths that look different in logs:
- A process exits with a non-zero status.
- The main process is terminated by a signal, subject to systemd’s documented clean-signal exceptions.
- An operation timeout expires.
- A service watchdog timeout occurs.
An administrator-issued systemctl stop example.service is intentional and does not trigger the restart policy. This distinction lets an operator stop a service for maintenance without having systemd immediately start it again.
A clean exit is different. Restart=on-failure normally leaves the service stopped when it exits successfully. That behavior is usually right for daemons that should remain running only while healthy. If a program is designed to exit cleanly and still needs to be relaunched, a different policy may be appropriate, but verify that behavior first so a normal shutdown does not become an endless restart cycle.
Choosing the restart policy
The three policies most often confused are on-failure, on-abnormal, and always. Their practical differences are summarized here.
| Policy | Restarts after | Clean exit remains stopped? | Timeout and watchdog recovery | Typical use |
|---|---|---|---|---|
on-failure |
Non-zero exit, abnormal signal termination, operation timeout, or watchdog timeout, with documented clean-signal exceptions | Yes | Yes | Default choice for most long-running daemons |
on-abnormal |
Abnormal signal termination, operation timeout, or watchdog timeout; it does not cover every non-zero exit | Yes | Yes | When ordinary error exits should be investigated rather than immediately relaunched |
always |
Both successful and unsuccessful exits, apart from an administrator stop | No | Yes | Programs that are expected to run continuously even after a clean exit |
For a conventional server, on-failure is the least surprising starting point: it recovers from faults while preserving a deliberate or successful shutdown. Use always only when a clean exit is itself an event that should cause the process to return. Otherwise, a configuration error that makes the program exit successfully could be hidden by perpetual restarts.
Why use a drop-in instead of editing the unit file?
Distribution packages commonly install unit files under paths such as /usr/lib/systemd/system or /lib/systemd/system. Those files belong to the package. Editing one directly can work temporarily, but a package update may replace it and remove your restart policy.
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
A file under /etc/systemd/system/example.service.d/ has administrator precedence and is intended for local overrides. It leaves the packaged unit intact, keeps your change visible, and makes removal straightforward. To remove the policy later, delete the override file, run sudo systemctl daemon-reload, and restart the unit.
You can also create the same drop-in interactively with:
sudo systemctl edit example.service
That command opens an override editor and saves the result in the appropriate .service.d directory. Whether you create the file manually or use systemctl edit, the section must be [Service] and the directives must be spelled exactly.
Set a delay that prevents a crash loop
RestartSec= controls how long systemd waits before attempting a restart. A five-second delay is a reasonable example for many network daemons, but the correct value depends on the service:
- Use a short delay when recovery is quick and clients benefit from prompt availability.
- Use a longer delay when the service depends on a database, network mount, credentials service, or external endpoint that may need time to recover.
- Avoid a near-zero delay for a process that fails immediately. Rapid retries consume CPU, fill logs, and can make a host harder to diagnose.
- Consider startup time and shutdown cleanup. The delay begins after systemd has handled the failed attempt, not merely after the process printed an error.
A restart policy is not a substitute for fixing the cause. If each launch fails because a configuration file is invalid or a required path is missing, repeated attempts only obscure the first useful error.
Rate limits: why systemd eventually stops retrying
Systemd protects a host from an uncontrolled crash loop with start-rate limits. StartLimitIntervalSec= defines a time window, and StartLimitBurst= defines how many starts are allowed in that window. If the service fails repeatedly and reaches the burst limit, systemd stops scheduling further starts until the limit window passes or an operator resets the failed state.
This behavior can look like a broken Restart=on-failure setting: the first few crashes cause restarts, then the unit remains failed. Treat that transition as a diagnostic signal rather than immediately raising the limits.
Inspect the limit and failure state
systemctl status example.service
systemctl show example.service -p Restart -p RestartUSec -p StartLimitIntervalUSec -p StartLimitBurst
journalctl -u example.service -b --no-pager
The exact property names shown by systemctl show can vary with the installed systemd version. The status output normally reports that start requests were repeated too quickly when the rate limit is the reason no new attempt was made.
Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
Find the first failure, not only the last one
Look backward in the journal to the first launch that failed. Check the exit status, signal, permission errors, missing files, invalid arguments, dependency failures, and environment differences between an interactive shell and a system service:
journalctl -u example.service -bshows messages for the current boot.journalctl -u example.service --since "30 min ago"narrows the search to a recent incident.systemctl status example.serviceshows the last result and a short log excerpt.systemctl cat example.servicedisplays the vendor unit and drop-ins that systemd is using.
Correct the underlying problem, then clear the failed state and start the unit again:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →sudo systemctl reset-failed example.service
sudo systemctl start example.service
Only after understanding the failure should you deliberately adjust StartLimitIntervalSec= or StartLimitBurst=. Those settings are generally placed in the unit’s [Unit] section (or an appropriate manager configuration, depending on the installed systemd release). Raising them without fixing the fault can turn a short outage into a persistent resource and logging problem.
Watchdogs catch hangs that do not exit
A restart policy can act only on events systemd can observe. A process that has exited is observable; a process that is alive but unresponsive may not be. Systemd’s watchdog mechanism addresses that case when the service supports it.
Set WatchdogSec= to establish a deadline, then configure the application to send systemd keep-alive notifications. The application must actually implement those notifications; setting a watchdog interval alone does not make an arbitrary binary prove that it is healthy.
If the deadline is missed, systemd terminates the service and records a watchdog timeout. With Restart=on-failure, on-watchdog, on-abnormal, or always, that event can lead to a restart. Confirm that the application’s notification interval is comfortably shorter than the deadline and that the service can notify systemd from all relevant worker states. Otherwise, a watchdog can produce false failures or fail to detect the kind of hang you care about.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Verify that the override is active
Do not rely only on the presence of a file. Confirm that systemd loaded the value for the unit you are running.
-
Display the effective unit:
systemctl cat example.serviceLook for the drop-in path and the
[Service]lines. -
Query the effective restart settings:
systemctl show example.service -p Restart -p RestartUSecYou should see
Restart=on-failureand a restart delay corresponding to yourRestartSec=value.Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
-
Check whether the service is healthy now:
systemctl is-active example.service systemctl status example.service -
Follow events while reproducing a controlled failure in a maintenance window:
journalctl -fu example.service
A safe test depends on the application. Do not kill a production process merely to prove the policy works. If you have a staging instance, use the application’s documented failure or stop mechanism and observe whether systemd records the exit and schedules a restart. Remember that systemctl stop is intentionally excluded from automatic recovery.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallTroubleshooting when the service does not restart
The file was edited but nothing changed
Run sudo systemctl daemon-reload. Systemd does not automatically reread every unit file after a filesystem edit. Then restart the service and inspect systemctl cat to ensure the drop-in is in the correct directory and has a .conf extension.
The service exits cleanly
on-failure does not normally restart a successful exit. Check the result in systemctl status and the application’s own exit-code documentation. If clean exits are expected and must cause relaunch, evaluate Restart=always deliberately instead of assuming the service crashed.
An operator stop is mistaken for a crash
A manual systemctl stop is not a failure event. To bring the unit back, use sudo systemctl start example.service or sudo systemctl restart example.service. This behavior prevents maintenance commands from fighting the restart policy.
Restarts stopped after several attempts
Inspect the journal for a start-limit message and check StartLimitIntervalSec= and StartLimitBurst=. Reset the failed state after correcting the root cause. Do not mask the problem by setting an extremely high burst count.
Recommended Free Tools
The process starts and immediately fails again
Read the earliest failure in journalctl, then verify paths, ownership, permissions, environment variables, working directory, credentials, ports, and dependencies. A systemd service does not necessarily receive the same shell environment as the account that can start the program interactively. If the unit depends on another service, inspect ordering and requirement relationships rather than adding arbitrary delays.
The service is alive but frozen
A restart policy does not automatically detect every hung process. Add a supported watchdog configuration, ensure the application sends keep-alive notifications, and verify that a missed deadline produces a watchdog event in the journal. Without application support, use the service’s own health mechanism or an external monitor appropriate to your architecture.
Best Value
Dependencies and ordering still matter
Automatic restart only relaunches the unit. It does not repair a missing mount, create a database, renew credentials, or guarantee that a dependency is ready. Review the unit’s dependency and ordering directives with:
systemctl cat example.service
systemctl list-dependencies example.service
If a dependency is down, the restarted service may fail repeatedly and hit the start-rate limit. Fix the dependency relationship or its health first. A restart delay can give a dependency time to come up, but it should not be used to conceal incorrect ordering.
Running the service in Docker instead
Containers have a separate restart-policy mechanism. Docker documents on-failure[:max-retries], which restarts a container when its process exits with a non-zero status. The optional maximum limits how many attempts Docker makes.
| Question | Host systemd | Docker restart policy |
|---|---|---|
| What is supervised? | A host service process and its unit dependencies | A container’s foreground process |
| Failure policy | Restart=on-failure, with systemd start-rate limits |
on-failure[:max-retries], based on a non-zero container exit |
| Primary logs | journalctl -u example.service |
Container logs through Docker’s logging commands and configured driver |
| Dependency ordering | Systemd units and targets | Container configuration and the host/container orchestration layer |
| Process requirement | Systemd must be able to observe the service process | The application should stay in the foreground so Docker can observe its exit |
Choose one clear supervisory layer for each process. If Docker restarts a container and systemd also restarts a wrapper or container unit, the two policies can obscure which layer is responsible and produce competing retries. Docker’s documentation also notes that a process manager such as systemd or supervisor can manage a container or service when Docker’s own policies do not fit. Decide where retry limits, dependency ordering, and logs should live before enabling both layers.
Keep the container process in the foreground
A daemon that forks into the background can make a container appear healthy or exited at the wrong time. Run the application in foreground mode inside the container so Docker observes the real process status. Then select Docker’s restart policy or delegate supervision to a host manager, rather than layering policies without a reason.
Operational safeguards
- Log the cause: Keep the service’s standard output and error connected to the journal or an intentional logging destination so each restart has an observable reason.
- Preserve exit information: Check the unit result and exit code before changing policy. Different failures require different fixes.
- Avoid restart storms: Use a non-zero
RestartSec=value and respect start-rate limits. - Test upgrades: After a package update, run
systemctl catandsystemctl showto confirm the drop-in is still loaded. - Plan maintenance: Use
systemctl stopwhen you need the service to stay down; the restart policy will not override that deliberate action. - Limit privileges: Automatic recovery does not justify running the service as root. Keep the unit’s existing least-privilege settings unless the application requires otherwise.
- Document ownership: Record why the override exists, what delay was selected, and who should investigate repeated failures.
Removing or changing the policy
To change the delay, edit the drop-in and run:
sudo systemctl daemon-reload
sudo systemctl restart example.service
To remove the automatic restart entirely, delete the override and reload:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →sudo rm /etc/systemd/system/example.service.d/override.conf
sudo systemctl daemon-reload
sudo systemctl restart example.service
If the directory becomes empty, remove it as well. Confirm the effective value with systemctl show example.service -p Restart -p RestartUSec. The result should reflect the vendor unit’s setting or an empty/default value, depending on that unit.
Decision checklist
Before enabling automatic recovery, answer these questions:
- Is this a long-running service that should return after an unexpected failure?
- Should a successful exit remain stopped?
- What delay allows dependencies and resources to recover?
- What evidence will identify the first failure?
- Could repeated failures hit the start-rate limit?
- Does the application support watchdog notifications if hangs matter?
- Is Docker, systemd, or another manager the single owner of this process’s restart policy?
- Have you tested the behavior in a non-production environment?
For most systemd-managed daemons, the practical configuration remains:
[Service]
Restart=on-failure
RestartSec=5s
Apply it through a drop-in, reload systemd, restart the unit, and verify both status and journal output. Automatic restart improves availability only when the underlying failure remains visible and the retry behavior is bounded.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsQuick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




