systemd action when a service fails?

Viewed 98

Is there a standard way to get systemd to execute a command when a service fails? For example, send an email to somebody (or a passive alert to Nagios).

I realise I can write a wrapper around the ExecStart command, but I had hoped for something less ad-hoc.

1 Answers

OnFailure= A space-separated list of one or more units that are activated when this unit enters the "failed" state. A service unit using Restart= enters the failed state only after the start limits are reached.

Source: https://www.freedesktop.org/software/systemd/man/systemd.unit.html

Anyone with an elegant testing approach please append to my answer.

Related