Email on systemd Service Failure

Prerequisites: Email (msmtp)

We can set up systemd to notify us by email if it fails. Systemd actually does this by starting another service.

We can create the service at /etc/systemd/system/notify-email@.service

[Unit]
Description=Send email

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c 'printf "Subject: [systemd] %i Failed" | /usr/bin/msmtp default'

This can easily be tested with sudo systemctl start notify-email@test.

This notification method can be used by our other systemd services.

Backup

We add the files to our backup script:

    /etc/msmtprc \
    /etc/aliases \
    /etc/systemd/system/notify-email@.service \

results matching ""

    No results matching ""