Send emails OnFailure through dedicated service

The unit-status-email@.service allows being triggered through multiple services with @.
Note that everything after the @ is passed to the unit-status-email@.service as parameter.
We pass the complete service name OnFailure using %n.
The parameter can then be accessed by %i within the unit-status-email@.service.
Hence, to pass the service name to our email script for processing we use %i within unit-status-email@.service.
This commit is contained in:
Daniel Karzel 2021-02-24 12:12:38 +11:00
commit fbd0eb7548
5 changed files with 11 additions and 5 deletions

View file

@ -1,11 +1,11 @@
[Unit]
Description=Restart ASB service
After=watch-asb-binary-change.path
OnFailure=unit-status-email@%n.service
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart start-asb.service
ExecStopPost=/bin/sh -c 'if [ "$$EXIT_STATUS" -ne 0 ]; then /usr/local/bin/systemd-email.sh daniel@coblox.tech %n; fi'
[Install]
WantedBy=multi-user.target