The systemd.service
man page has a description of the values Restart=
takes, and a table of what options cause a restart when. Always
pretty much does what it says on the lid:
If set to always
, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.
I don't know for sure what situation they had in mind for that feature, but we might hypothesise e.g. a service configured to only run for a fixed period of time or to serve fixed number of requests and to then stop to avoid any possible resource leaks. Having systemd do the restarting makes for a cleaner implementation of the service itself.
In some sense, we might also ask why not include that option in systemd. Since it is capable of restarting services on failure, they might as well include the option of restarting the service always, just in case someone needs it. To provide tools, not policy.
Note also that a "successful exit" here is defined rather broadly:
If set to on-success
, it will be restarted only when the service process exits cleanly. In this context, a clean exit means an exit code of 0, or one of the signals SIGHUP
, SIGINT
, SIGTERM
or SIGPIPE
, [...]
SIGHUP
is a common way of asking a process to restart, but it unhandled, it
terminates the process. So having Restart=always
(or Restart=on-success
) allows to use SIGHUP
for restarting, even without the service itself supporting that.
Also, as far as I can read the man page, always
doesn't mean it would override the limits set by StartLimitInterval
and StartLimitBurst
:
Note that service restart is subject to unit start rate limiting configured with StartLimitIntervalSec=
and StartLimitBurst=
, see systemd.unit(5) for details. A restarted service enters the failed state only after the start limits are reached.
Reason=on-abort
as well. See https://unix.stackexchange.com/questions/564443/what-does-restart-on-abort-mean-in-a-systemd-service/564444#564444 – PatS Jan 27 '20 at 21:36