I'm using a systemd service. I want to execute a bash script when my systemd service goes down -- fails. I don't want to execute a bash script when I restart the service myself. But only when it or the process it supervices crashes by itself.

How can I do that? Should I use OnFailure? Or ExecStopPost?

Note that in my systemd service there's only ExecStart and no ExecStop


From what i could find on https://bbs.archlinux.org/viewtopic.php?id=169344 , using OnFailure= should be sufficient. It will run when the exit code of your service is non-zero. Although, I found no mention of this in the sytemd.service manpage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.