I'm trying to setup
systemd to notify me via email if a unit fails, like Cron can be set up to do. I followed the guide on the Arch Linux wiki.
So I set-up a
sendmail shell script in
#!/bin/bash /usr/bin/sendmail -t <<ERRMAIL To: $1 From: systemd <root@$HOSTNAME> Subject: $2 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 $(systemctl status --full "$2") ERRMAIL
And then I set-up a systemd service in
[Unit] Description=status email for %I to user1 [Service] Type=oneshot ExecStart=/usr/local/bin/systemd-email email@example.com %i User=nobody Group=systemd-journal
However, when I test this setup, running
systemctl start firstname.lastname@example.org, I get the following fail message:
email@example.com - status email for dbus to user1 Loaded: loaded (/etc/systemd/system/status-email-user1@.service; static; vendor preset: disabled) Active: failed (Result: exit-code) since Sun 2015-06-14 10:19:36 MDT; 20min ago Process: 31229 ExecStart=/usr/local/bin/systemd-email firstname.lastname@example.org %i (code=exited, status=1/FAILURE) Main PID: 31229 (code=exited, status=1/FAILURE) Jun 14 10:19:36 sindhu systemd: Starting status email for dbus to user1... Jun 14 10:19:36 sindhu sSMTP: /etc/ssmtp/ssmtp.conf not found Jun 14 10:19:36 sindhu sSMTP: Unable to locate mailhub Jun 14 10:19:36 sindhu systemd-email: sendmail: Cannot open mailhub:25 Jun 14 10:19:36 sindhu systemd: email@example.com: main pro...RE Jun 14 10:19:36 sindhu systemd: Failed to start status email for dbus to ...1. Jun 14 10:19:36 sindhu systemd: Unit firstname.lastname@example.org ente...1. Jun 14 10:19:36 sindhu systemd: email@example.com failed. Hint: Some lines were ellipsized, use -l to show in full.
/etc/ssmtp/ssmtp.conf is in fact present, and configured properly (I already have SSMTP set up), and so if I run something like:
echo -e "To: firstname.lastname@example.org\nFrom: email@example.com\nSubject: Hello Notification\n\n Hello, this is a test"|ssmtp firstname.lastname@example.org
I get email as expected/desired.
Likewise, if I run the shell script
systemd-email email@example.com dbus, I also get email.
So, all of the
systemd-external pieces seem to be working; it therefore must be something within
systemd, as far as I can make out. But I'm at a lost to know what, or how to fix it.