6

I'm using a service and it is dying (stopping) unexpectedly. I want to get it to restart automatically no matter how it stops! It is configured for Restart=on-abort and it is not restarting. I didn't write the service, it came from another vendor so while I want to track down the root cause of the service crashing, I also need a solution to keep the system running until I can find the root cause. The service dies zero to three times a day so not too frequently.

The service currently is set to Restart=on-abort as defined in the service file at /etc/systemd/system/someone-elses.service

So what does Restart=on-abort mean?

I did a search and to learn what the different values of restart= mean and found nothing in the man page:

PatS
  • 604

1 Answers1

12

The systemd.service can be configured to restart a service based on a number of conditions. This systemctl man page has a good explanation of the reasons and reasons are included in this answer so this answer can stand alone.

The definition for Restart=on-abort is the service will be restarted only if the service process exits due to an uncaught signal not specified as a clean exit status. This means a signal other than SIGHUP, SIGINT, SIGTERM or SIGPIPE. These 4 signals are described as clean signals by the systemctl man page.

In my case I actually wanted Restart=always because regardless of how the process died or exited, I wanted it to be restarted. The property RestartSec=15s is important for me because I want some time between restarts to prevent constently restarting (I don't expect this to happen but that is why I have this setting).

The following is take from the systemctl man page and formatted for SO:

Restart= values can be no, on-success, on-failure, on-abnormal, on-watchdog,on-abort, or always.

Each of these values is explained next:

no (the default) - If set to no the service will not be restarted.

success - 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, and additionally, exit statuses and signals specified in SuccessExitStatus=.

on-failure - If set to on-failure, the service will be restarted when the process exits with a non-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned four signals), when an operation (such as service reload) times out, and when the configured watchdog timeout is triggered.

on-abnormal - If set to on-abnormal, the service will be restarted when the process is terminated by a signal (including on core dump, excluding the aforementioned four signals), when an operation times out, or when the watchdog timeout is triggered.

on-abort - If set to on-abort, the service will be restarted only if the service process exits due to an uncaught signal not specified as a clean exit status. If set to on-watchdog, the service will be restarted only if the watchdog timeout for the service expires.

always - 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.

See also this wonderful answer! https://unix.stackexchange.com/a/507917/119816

PatS
  • 604