I want systemd to start a script and retry a maximum of 5 times, 30s apart. Reading the systemd.service manual and searching the Internet didn't produce any obvious answers.
Systemd makes it very easy to restart a unit when it fails. Sometimes, this is all you really need.
StartLimitInterval=, StartLimitBurst= Configure service start rate limiting. By default, services which are started more than 5 times within 10 seconds are not permitted to start any more times until the 10 second interval ends. With these two options, this rate limiting may be modified.
Delay the start of the systemd service at boot. Inspect service that you want to delay at boot. redis-server. service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.
After much trial and error I solved my problem and thought it worth posting here...
To allow a maximum of 5 retries separated by 30 seconds use the following options in the relevant systemd service file.
[Unit] StartLimitInterval=200 StartLimitBurst=5 [Service] Restart=always RestartSec=30
This worked for me for a service that runs a script using 'Type=idle'. Note that 'StartLimitInterval' must be greater than 'RestartSec * StartLimitBurst' otherwise the service will be restarted indefinitely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With