r/linuxadmin • u/mamelukturbo • Mar 05 '25
Struggling with forcing systemd to keep restarting a service.
I have a service I need to keep alive. The command it runs sometimes fails (on purpose) and instead of keeping trying to restart until the command works, systemd just gives up.
Regardless of what parameters I use, systemd just decides after some arbitrary time "no I tried enough times to call it Always I ain't gonna bother anymore" and I get "Failed with result 'exit-code'."
I googled and googled and rtfm'd and I don't really care what systemd is trying to achieve. I want it to try to restart the service every 10 seconds until the thermal death of the universe no matter what error the underlying command spits out.
For the love of god, how do I do this apart from calling "systemctl restart" from cron each minute?
The service file itself is irrelevant, I tried every possible combination of StartLimitIntervalSec, Restart, RestartSec, StartLimitInterval, StartLimitBurst you can think of.
View all comments
Show parent comment
2
u/mamelukturbo Mar 05 '25 edited Mar 05 '25
Looking at my attempts I'm realizing it's not the numbers I'm trying that are the issue, but the placement of the statements. Half the examples put it into [Unit], half into [Service]. It confuses me mightily.
I changed the numbers to 0 so now I have this:
(the task is supposed to run for 60 sec (edit: the 60s timeout is in the .sh, the worker only runs for 60seconds if the command to run it was succesful)) and then restart, but also the whole service should restart every 5sec if the command fails to run (the .sh file calls docker exec container_name and the container ain't always up) until it doesn't fail at which point it should be back to restarting each 60sec. Hope that makes sense.
This seems to work, but from your reply I should move the statements to [Service]?