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.
1 Answer
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.
-
8It's maybe worth noting that -- according to the official systemd manpages -- RestartSec and Restart are part of [System], whereas StartLimitInterval and StartLimitBurst are part of [Unit]. Jun 14, 2017 at 12:26
-
9
-
12@GerhardHagerer When you say [System], I think you mean [Service]. This worked for me.– HaakonJan 9, 2018 at 10:34
-
4
-
4also, more details here: freedesktop.org/software/systemd/man/systemd.unit.html# and here: freedesktop.org/software/systemd/man/…– fei0xFeb 15, 2018 at 22:11
immortal -w 30 -r 5 <your command>