2

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.

j4nd3r53n
  • 680
  • 2
  • 11
  • 26

1 Answers1

2

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

One hacky way to test failures is to run the service with User=Dummy and then, while the service is running, destroy or modify the user Dummy using the command line.

jprio
  • 97
  • 1
  • 13