Using nullmailer as a Reboot Alerter

I use postfix with an encrypted mailstore. For security reasons, I don't keep the private key anywhere on the mail system, so if for any reason the system reboots, I need to first unencrypt the mailstore before I can start postfix. Nullmailer fits in as an alerter, sending me an "MTA-less" email that I need to take some action to get my mailsystem back up and running.

Installing nullmailer

Nullmailer can installed from a package manager or from source. It may need to be installed by hand if it conflicts with any other existing MTA packages on the system. Nullmailer can be downloaded from http://untroubled.org/nullmailer/. Installation is clean and simple, just follow the instructions in the HOWTO file.

Add in a shell script, /usr/local/bin/genmail.sh to generate the alert email.

#!/bin/bash
# START OF USER CHANGABLE VARIABLES
sender=root@"YOUR SYSTEM'S EMAIL ADDRESS HERE"
alertemail="YOUR EMAIL ADDRESS HERE"
alertname="NAME OF PERSON TO BE ALERTED"

yourname="ALERTER'S NAME HERE"
#  END  OF USER CHANGABLE VARIABLES


emailfile=/tmp/reboot-email.tmp
HOSTNAME=`hostname`
dtime=`date`
ltlt="<"
gtgt=">"

echo "Subject: SYSTEM REBOOTED at $dtime" > $emailfile
echo "From: $yourname  $ltlt$sender$gtgt" >> $emailfile
echo "To: $alertname  $ltlt$alertemail$gtgt" >> $emailfile
echo "" >> $emailfile
echo "$HOSTNAME rebooted at $dtime" >> $emailfile
echo "" >> $emailfile
echo "Sincerely" >> $emailfile
echo "$yourname" >> $emailfile


cat $emailfile | /usr/local/nullmailer/bin/nullmailer-inject -h 

Add a few lines to /etc/rc.local (or equivalent) to indicate a reboot. This starts nullmailer, sends the email alert, waits a few seconds, and then kills the nullmailer process that was started.

/usr/local/nullmailer/sbin/nullmailer-send &
/usr/local/bin/genmail.sh
sleep 3
/usr/bin/killall /usr/local/nullmailer/sbin/nullmailer-send
sleep 1
/usr/bin/killall nullmailer-send

Test by running /etc/rc.local or rebooting.