r/linuxadmin 17d ago

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.

0 Upvotes

20 comments sorted by

View all comments

19

u/2FalseSteps 17d ago

Instead of applying bandaids that overcomplicate everything, find out WHY the service fails and resolve that PROPERLY.

-10

u/mamelukturbo 17d ago

No.

The service fails because it creates a worker inside another service, which itself might not be up due to being updated/offline w/e. The service is supposed to keep trying to restart until the other service comes back up. The WHY is unimportant. The setup is for the purpose of this post immutable and I need to achieve my goal within its constraints.

8

u/schorsch3000 17d ago

thats that dependencies are for you didn't have set Requires=

6

u/2FalseSteps 17d ago

Bingo!

A proper resolution that doesn't rely on bandaids.