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 /usr/local/bin/systemd-email:
#!/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 /etc/systemd/system/[email protected]:
[Unit]
Description=status email for %I to user1
[Service]
Type=oneshot
ExecStart=/usr/local/bin/systemd-email [email protected] %i
User=nobody
Group=systemd-journal
However, when I test this setup, running systemctl start [email protected], I get the following fail message:
[email protected] - status email for dbus to user1
Loaded: loaded (/etc/systemd/system/[email protected]; 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 [email protected] %i (code=exited, status=1/FAILURE)
Main PID: 31229 (code=exited, status=1/FAILURE)
Jun 14 10:19:36 sindhu systemd[1]: Starting status email for dbus to user1...
Jun 14 10:19:36 sindhu sSMTP[31230]: /etc/ssmtp/ssmtp.conf not found
Jun 14 10:19:36 sindhu sSMTP[31230]: Unable to locate mailhub
Jun 14 10:19:36 sindhu systemd-email[31229]: sendmail: Cannot open mailhub:25
Jun 14 10:19:36 sindhu systemd[1]: [email protected]: main pro...RE
Jun 14 10:19:36 sindhu systemd[1]: Failed to start status email for dbus to ...1.
Jun 14 10:19:36 sindhu systemd[1]: Unit [email protected] ente...1.
Jun 14 10:19:36 sindhu systemd[1]: [email protected] failed.
Hint: Some lines were ellipsized, use -l to show in full.
But, /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: [email protected]\nFrom: [email protected]\nSubject: Hello Notification\n\n Hello, this is a test"|ssmtp [email protected]
I get email as expected/desired.
Likewise, if I run the shell script systemd-email [email protected] 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.