systemd gives up trying to restart it
No. systemd gives up trying to restart it for a little while. This is clearly shown in the log that you supply:
Jun 14 11:25:51 localhost systemd: test.service: Failed with result 'start-limit'.
This is rate limiting kicking in.
The length of the little while is specified in the service unit, using the
StartLimitIntervalSec= setting. The number of starts that are needed within that interval to trigger the rate limiting mechanism are specified via the
StartLimitBurst= setting. If nothing on your system differs from vanilla systemd, including the defaults for these two settings, then it is 5 times within 10 seconds.
StartLimitIntervalSec=0 disables rate limiting. But making your service either not exit so often, or idle enough between exits and restarts that it does not exceed the rate limiting threshold, is a better approach.
Note that rate limiting does not care how your service exited. It triggers on the number of attempts to start/restart it, irrespective of their cause.
- Lennart Poettering (2013-10-07).
systemd.unit. systemd manual pages. freedesktop.org.
- Systemd's StartLimitIntervalSec and StartLimitBurst never work