Run script when systemd service fails

2

I'm running Debian 8 on a server.

How do I run a bash script if a systemd controlled service fails to start or restart?

Similarly if a service suddenly stops and cannot continue. In effect I want to run a script no matter how the service fails.

fswings

Posted 2016-01-23T23:30:19.317

Reputation: 666

duplicate: Run an arbitrary command when a service fails

– phuclv – 2017-06-14T07:30:28.843

Answers

1

I can't comment but...

Have you tried using OnFailure= in the [Unit] section?

aiguofer

Posted 2016-01-23T23:30:19.317

Reputation: 211

Thanks for the suggestion. Anyway I can test it easily m – fswings – 2016-01-31T13:31:00.933