0

Controlled restart of a systemd managed service? I have a service that I want to have restart by default if it fails, but not if a specific condition is encountered. Using Restart=ab-normal or Restart=always works but I want to stop halt the restart if a specific condition is encountered. This is use full of the service should always restart except when the applicable hardware related to the service has failed for example. Unfortunately, Restart=ab-normal or Restart=always does not seem to have any intelligence? Even if I write code logic to return a specific exit code, say 255, the Restart= parameter ignores such, and via code can't seem to find a way to control this in my code? I guess what or need is Restart=always unless exit code = 255, type of thing? Is there some way to implement this concept?

1 Answer 1

1

systemd services have a RestartPreventExitStatus option:

Takes a list of exit status definitions that, when returned by the main service process, will prevent automatic service restarts, regardless of the restart setting configured with Restart=. Exit status definitions can either be numeric exit codes or termination signal names, and are separated by spaces. Defaults to the empty list, so that, by default, no exit status is excluded from the configured restart logic.

So if your service can be modified to return a specific exit code, (say 255 as in your question), you can set

RestartPreventExitStatus=255

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .