Get notification when systemd-monitored service enters failed state

Just my way to notify :

/etc/systemd/system/notify-email@.service

[Unit]
Description=Sent email 

[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c '/usr/bin/systemctl status %i | /usr/bin/mailx -Ssendwait -s "[SYSTEMD_%i] Fail" your_admin@company.blablabla'

[Install]
WantedBy=multi-user.target

add to systemd, example for ntpd.service:

systemctl enable /etc/systemd/system/notify-email@ntpd.service

At others services add:

systemctl edit ntpd

[Unit] OnFailure=notify-email@%i.service

Reload the configuration:

systemctl daemon-reload
Topic revision: r2 - 26 Mar 2024, Dibiase
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Wiki_Virgo_LSC? Send feedback