I'm using systemd to keep a worker script working at all times:[Unit]Description=My workerAfter=mysqld.service[Service]Type=simpleRestart=alwaysExecStart=/path/to/script[Install]WantedBy=multi-user.targetAlthough the restart works fine if the script exits normally after a few minutes, I've noticed that if it repeatedly fails to execute on startup, systemd will just give up trying to start it:Jun 14 11:10:31 localhost systemd[1]: test.service: Main process exited, code=exited, status=1/FAILURE  Jun 14 11:10:31 localhost systemd[1]: test.service: Unit entered failed state.  Jun 14 11:10:31 localhost systemd[1]: test.service: Failed with result 'exit-code'.  Jun 14 11:10:31 localhost systemd[1]: test.service: Service hold-off time over, scheduling restart.  Jun 14 11:10:31 localhost systemd[1]: test.service: Start request repeated too quickly.  Jun 14 11:10:31 localhost systemd[1]: Failed to start My worker.  Jun 14 11:10:31 localhost systemd[1]: test.service: Unit entered failed state.  Jun 14 11:10:31 localhost systemd[1]: test.service: Failed with result 'start-limit'.Similarly, if my worker script fails several times with an exit status of 255, systemd gives up trying to restart it:Jun 14 11:25:51 localhost systemd[1]: test.service: Failed with result 'exit-code'.  Jun 14 11:25:51 localhost systemd[1]: test.service: Service hold-off time over, scheduling restart.  Jun 14 11:25:51 localhost systemd[1]: test.service: Start request repeated too quickly.  Jun 14 11:25:51 localhost systemd[1]: Failed to start My worker.  Jun 14 11:25:51 localhost systemd[1]: test.service: Unit entered failed state.  Jun 14 11:25:51 localhost systemd[1]: test.service: Failed with result 'start-limit'.Is there a way to force systemd to always retry after a few seconds?
Systemd Restart=always is not honored
systemd
I would like to extend Rahul's answer a bit.systemd tries to restart multiple times (StartLimitBurst) and stops trying if the attempt count is reached within StartLimitIntervalSec. Both options belong to the [unit] section.The default delay between executions is 100ms (RestartSec[2]) which causes the rate limit to be reached very fast.systemd won't attempt any more automatic restarts ever for units with Restart policy defined [1]:Note that units which are configured for Restart= and which reach the  start limit are not attempted to be restarted anymore; however, they   may still be restarted manually at a later point, from which point on,   the restart logic is again activated. Rahul's answer helps, because the longer delay prevents reaching the error counter within the StartLimitIntervalSec time. The correct answer is to set both RestartSec and StartLimitBurst to reasonable values though.[1] https://www.freedesktop.org/software/systemd/man/systemd.unit.html#StartLimitIntervalSec=[2] https://www.freedesktop.org/software/systemd/man/systemd.service.html#RestartSec=