I need to have network messages sent when a systemd service I have crashes or is hung (i.e., enters failed state; I monitor for hung by using WatchdogSec=). I noticed that newer systemd have FailureAction=, but then saw that this doesn't allow arbitrary commands, but just rebooting/shutdown.
Specifically, I need a way to have one network message sent when systemd detects the program has crashed, and another when it detects it has hung.
I'm hoping for a better answer than "parse the logs", and I need something that has a near-instant response time, so I don't think a polling approach is good; it should be something triggered by the event occurring.
notify%n.serviceis redundant, and will result innotify@my-service.service.service. Second,%ishould be used instead of%I, or all dashes in the name will be converted to forward slashes. – orodbhen Jun 22 '16 at 15:42systemctl edit my-service.serviceand in the editor that opens add a line[Unit]followed byOnFailure=notify-failed@%n, save and exit. This will create an override file in/etc/systemd/system/my-service.service.d/override.confwith the added functionality (of course you can automate the creation of such files for multiple services, just don't forget to dosystemctl daemon-reloadif you modified files not throughsystemctl). – Guss Feb 06 '22 at 11:41service.ddirectory and it will apply to all services. – Felipe May 19 '22 at 17:59OnFailure= failure-handler@%n.servicedoes work when attached to the individual service's[Unit]section but not when/etc/systemd/system/service.d/10-all.confis the only place it is defined. – cueedee Feb 07 '23 at 08:03systemdversion 244 or newer and Ubuntu 18 only has version 237. – cueedee Feb 09 '23 at 21:09