Since Ubuntu makes use of Upstart, I decided to take some time to figure out how to write a job to send a notification email every time one of my servers reboots. The Upstart job is below and is stored in
# boot-notify - sends an email notification upon boot
description "sends an email notification upon boot"
start on started rc-sysinit
exec echo "$( hostname -f ) booted on $( date )" | mail -s "$( hostname -f ) booted" root
Here’s a brief explanation: The line
start on started rc-sysinit says this job can’t run until after rc-sysinit has completed. I use Postfix, which still uses the init daemon. Therefore, it was easiest to send an email after the init daemon gets done running its jobs including starting Postfix. The
task line simply says this is a short running process that doesn’t continue running the way a service would. The last line is the command to run identified by