systemd-unit-status-mail icon indicating copy to clipboard operation
systemd-unit-status-mail copied to clipboard

Be notified via e-mail when a systemd unit enters failed state.

systemd-unit-status-mail

Be notified via e-mail when a systemd unit enters failed state. Based on this blog post.

Installation

  1. Decide where you want to install things.

    INSTALL_DIR=/usr/local/src/systemd-unit-status-mail
    
  2. Clone this repository.

    $ git clone https://github.com/agross/systemd-unit-status-mail.git "$INSTALL_DIR"
    Cloning into 'systemd-unit-status-mail'...
    
  3. Install the systemd unit.

    $ "$INSTALL_DIR/install"
    Linking /usr/local/src/systemd-unit-status-mail/[email protected]
    Linking /usr/local/src/systemd-unit-status-mail/unit-status-mail
    
  4. Tell [email protected] who should receive notifications.

    $ systemctl edit [email protected]
    
    # Editor opens. Add these lines and save the file.
    
    [Service]
    [email protected],[email protected]
    
  5. Configure units that you want to be notified about.

    $ systemctl edit some.service
    
    # Editor opens. Add these lines and save the file.
    
    [Unit]
    OnFailure=unit-status-mail@%n.service
    

Optional configuration items to think about

Test your setup

$ UNIT=auditd.service
$ systemctl start unit-status-mail@$UNIT.service
$ systemctl status unit-status-mail@$UNIT.service
● [email protected] - Unit Status Mailer Service
   Loaded: loaded (/usr/local/src/systemd-unit-status-mail/[email protected]; linked; vendor preset: disabled)
  Drop-In: /etc/systemd/system/[email protected]
           └─override.conf
   Active: inactive (dead)

Jan 22 18:45:11 fedja.wghoch4.local systemd[1]: Starting Unit Status Mailer Service...
Jan 22 18:45:11 fedja.wghoch4.local unit-status-mail[13876]: <13>Jan 22 18:45:11 /etc/systemd/system/unit-status-mail: Status mail sent to [email protected],[email protected] for unit auditd.service
Jan 22 18:45:13 fedja.wghoch4.local systemd[1]: Started Unit Status Mailer Service.

Getting the whole picture

To get all [email protected] settings use