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?
4 Answers
Dude, I totally get your struggle! Systemd can be as stubborn as a mule sometimes, acting like it knows best.
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.
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!
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.
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!
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.
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.
Thanks for the tip! I might have misunderstood where to place parameters. Shouldn't some of them go into the [Unit] section?