How to configure systemd service to retry 5 times in 30 seconds

I want systemd to run a script and retry a maximum of 5 times, 30 seconds apart. Reading the systemd.service manual and searching the Internet did not give any obvious answers.

+5
source share
1 answer

After much trial and error, I solved my problem and thought it was worth posting here ...

To allow a maximum of 5 repetitions divided by 30 seconds, use the following parameters in the corresponding 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'. Please note that "StartLimitInterval" must be larger than "RestartSec * StartLimitBurst", otherwise the service will be restarted indefinitely.

+12
source

All Articles