How can I force systemd to constantly restart a failing service?

April 23, 2025 4 answers
Asked by TechyExplorer42
I'm having a tough time getting systemd to keep trying to restart a service that occasionally fails on purpose. Instead of continuously attempting to restart the service, systemd seems to give up after a certain number of attempts and gives me the message "Failed with result 'exit-code'." I really want it to keep trying every 10 seconds until it eventually succeeds or until the end of time, regardless of the errors that the command produces. I've explored many parameter combinations like StartLimitIntervalSec, Restart, RestartSec, StartLimitInterval, and StartLimitBurst with no success. Is there a way to achieve this without resorting to using a cron job to manually restart it every minute?

Answers

ProblemSolver99
Instead of trying to patch things up too much, it might be worth figuring out why the service is failing in the first place and addressing that directly. Sometimes the underlying issue can be resolved for good!

FrustratedAdmin23: It's not that simple! The app is poorly written and there's nothing we can do since the developer won't fix it. I've been in countless meetings where the focus is on 'quick fixes' rather than real solutions, and it gets frustrating.

SolutionSeeker88: Agreed, sometimes workarounds just have to be implemented to deal with these unfixable issues. Sometimes you just have to make things work within the current setup.

Reply to this answer
LinuxNinja101
To keep your service restarting indefinitely with a delay, try modifying your service file to include `Restart=always` and `RestartSec=10s`. For example: ``` [Unit] Description=Indestructible Service After=network.target [Service] ExecStart=/path/to/your/command Restart=always RestartSec=10s [Install] WantedBy=multi-user.target ``` Make sure to reload systemd after changes with `sudo systemctl daemon-reload` and start your service using `sudo systemctl start myservice`. This should help you achieve your goal!

CuriousGeorge16: Thanks for the tip! I might have misunderstood where to place parameters. Shouldn't some of them go into the [Unit] section?

KeepItSimple90: Thatโ€™s definitely something to keep in mind! Itโ€™s easy to mix up section placements; many examples are out there but not always consistent.

Reply to this answer
TechWhiz99
Also, one thing to keep in mind is to set `StartLimitInterval=0` and `StartLimitBurst=0` if you want to fully disable the rate limiting aspect of systemd.
Reply to this answer
ServerGuruX
Dude, I totally get your struggle! Systemd can be as stubborn as a mule sometimes, acting like it knows best.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions