Since the beginning,
systemd had a Restart= directive to do just that – restart a service when it fails or exists. Some tuning was provided by RestartSec= (how long to wait between restarts), StartLimitBurst= (how many times to try) and few minor directives.
systemd v254, we have two new knobs:
RestartSteps= the number of steps to take to increase the interval of auto-restarts
RestartMaxDelaySec= the longest time to sleep before restarting a service as the interval goes up
Together, they provide ability to exponentially extend wait-time between restarts. First restart is quite quick, but then system waits more and more. Here what it means.
Let assume a service with following settings:
Restart=always RestartSec=100ms (the default) RestartMaxDelaySec=10s RestartSteps=5
Upon a failure,
systemd will wait (rounded a bit):
100ms until first restart
250ms until next restart (first step)
630ms until next restart (second step)
1.58s until next restart (third step)
3.98s until next restart (fourth step)
10.0s until next restart (
RestartSteps=5– fifth step) and following restarts
Second example. Given:
RestartSec=1s RestartMaxDelaySec=10s RestartSteps=3
subsequent restarts will be done after waiting:
2.15s (step 1)
4.64s (step 2)
10.0s (step 3, as in
Hope this helps. You can find the exact formula in src/core/service.c.