From the Canyon Edge -- :-Dustin

Wednesday, July 20, 2011

Introducing bootmail!



I have a handful of remote Ubuntu Servers floating around the Cloud, and even a couple of co-lo's at friends' houses.  All of these machines are very much "unattended", and I really don't like it when they get rebooted (unless I pulled that trigger)!

For this reason, I often added a cronjob to these systems to email me when they get rebooted.  It used to look something like this:

@reboot echo "$(hostname) rebooted on $(date)" | \
  mail -s "reboot notice [$(hostname)]" kirkland@example.com

Of course, I don't like duplicating code all over the place, and I love providing fun little utilities to all of you, so I improved upon this and just uploaded a new package to Ubuntu called bootmail.

You can already install it in Ubuntu 11.10 (Oneiric) with:

sudo apt-get install bootmail

Or you can install it on any older Ubuntu release with:

sudo apt-add-repository ppa:bootmail/ppa
sudo apt-get update
sudo apt-get install bootmail

Note that you'll be prompted by debconf to enter your email address, where bootmail will contact you when your system boots.


And now, each time I boot, I get an email that looks like this:

To: kirkland@example.com
Subject: bootmail: [mirror] booted on [Tue Jul 19 19:19:44 CDT 2011]
Message-Id: ...
Date: Tue, 19 Jul 2011 19:19:53 -0500 (CDT)
From: noreply@mirror (Bootmail)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

bootmail: [mirror] booted on [Tue Jul 19 19:19:44 CDT 2011]


==================
[/var/log/boot.log]:
==================
fsck from util-linux-ng 2.17.2
fsck from util-linux-ng 2.17.2
fsck from util-linux-ng 2.17.2
/dev/sda5 has been mounted 26 times without being checked, check forced.
/dev/sda6 has been mounted 26 times without being checked, check forced.
/dev/sda1: clean, 286/61312 files, 61620/244983 blocks
/dev/sda5: 222672/610800 files (0.1% non-contiguous), 1564984/2441872 blocks
/dev/sda6: 153602/29859840 files (1.3% non-contiguous), 67313156/119409129 blocks
init: ureadahead-other main process (880) terminated with status 4
/var/lib/tftpboot missing, aborting.
init: tftpd-hpa main process (907) terminated with status 1
init: tftpd-hpa main process ended, respawning
squid[931]: Squid Parent: child process 941 started
 * Starting AppArmor profiles       [80G [74G[ OK ]
 * Setting sensors limits       [80G [74G[ OK ]
 * Exporting directories for NFS kernel daemon...       [80G [74G[ OK ]
 * Starting NFS kernel daemon       [80G [74G[ OK ]
 * Not starting internet superserver: no services enabled
 * Starting Postfix Mail Transport Agent postfix       [80G [74G[ OK ]
 * Starting the landscape-client daemon       [80G [74G[ OK ]
 * Starting web server apache2       [80G apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[74G[ OK ]
==================


==================
[/etc/motd]:
==================
Linux mirror 2.6.32-33-server #70-Ubuntu SMP Thu Jul 7 22:28:30 UTC 2011 x86_64 GNU/Linux
Ubuntu 10.04.3 LTS

Welcome to the Ubuntu Server!
 * Documentation:  http://www.ubuntu.com/server/doc

  System information as of Tue Jul 19 19:19:44 CDT 2011

  System load:  1.06              Processes:           150
  Usage of /:   63.5% of 9.17GB   Users logged in:     0
  Memory usage: 12%               IP address for eth1: 10.1.1.11
  Swap usage:   0%

  Graph this data and manage this system at https://landscape.canonical.com/

==================

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQIcBAEBAgAGBQJOJh8oAAoJEEO1OJF3xoN1L5QQAKTrk16WfeDjt+2VaxxL/v0x
Pe2i/nZSND+rsvs7MEfEZ2iMJ/2IVFiqH14sT6oYEa8kc/WGffr1A6++vNjUe74E
EhMYwNKPby8RE8GwnItVDth95rXWwucuYRQoG9aMOI5b9xJvkdCyPVBJRlgohZzT
E2zsJqiPDQZFtVQ5HgNrXaxj2sqom6ZTCUZfb+/J5V3EGwy1Da9PL+jb5/ELNXiI
SKzWU79ryporwlwMy7E7+sFNfzyosn1PtzXshwT2M8pmPZpJtw86deN/ifRDn2DO
YxwYbG53WUveMzWpPQaIyVfLHlFDQcpC5PVhA0jHVfby5+qHyj5dnYQMeFiiDKIf
RmaA+r+F+oEKq9KFD/Go1PIuNgEFKDfdqAFsHsW90I59R3dppDOuyt0wHpNuddEs
qpIFNa+6uE5wj2MtZ0P6H0NfizRFxm8UYDlPjrsD2YaI7kCrUdEg0POpysE6FJdA
PDX9knZqIQ41KKNNSNat/Rh2mExUvKxTzYPkriWZ1WR6/SDlC7GvBhgUI8Xr9lJF
KbGgUCQbGizV4m6P/gv/50PEvG6LTeEVO6SzqIpblRAMDmm+CqKJC1w5HIaaH6Li
VUwnOqD3a1j9DeoCj0s2boqH3HKzpA97BIcP9OHAIYZaFg+86ZYnftuQmXHSkTEE
yLDsFpmQzunxOSSV05zF
=AI6b
-----END PGP SIGNATURE-----

So I get a date and timestamp, the hostname of the system that booted, and a couple of log files (which are configurable in /etc/bootmail/logs) every time the system boots (thanks for the suggestion, Clint) -- pure awesome for my unattended servers!

I also get a cryptographic signature of the entire message, signed by a GPG key uniquely generated for this local root user.  That piece is handled by another new utility that I've written for Ubuntu, called rootsign.  More about rootsign in my next post ;-)

Is there anyone out there that would use bootmail?

I was thinking about adding some support for bootmail in cloud-init, so that you could pass an email address to your instance through metadata, and it would email you as soon as its up.  What do you think?

Cheers,
:-Dustin