I have read the systemd man pages and also some Q&A here related to StartLimit*
I tried what is recommended for newer versions:
[Unit]
StartLimitBurst=5
StartLimitIntervalSec=90
[Service]
RestartSec=5
Restart=always
Also, what is supposed to work for older versions of systemd
:
[Service]
StartLimitBurst=5
StartLimitInterval=90
...
RestartSec=5
Restart=always
(this is still accepted and systemd-analyze
does not show any errors)
But neither of this works! i.e. my daemon keeps indefinitely restarting
I can see NRestarts
also showing the correct count.
I am on version systemd 237
on Ubuntu 18.04
(Bionic). I don't mind using either
format, but I want to make sure that the restart attempt is capped to 5 or 6 times
and no more.
I think the configuration you shared works. You probably need to share more details about the service.
Here are the test steps I ran. I used Ubuntu 18.04 (
systemd 237-3ubuntu10.53
).Create a basic shell script to run as a service.
Create a basic service.
Start the service.
The logs indicate the service was started 5 times and then went into a failed state.