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

17 comments:

  1. I really like your tools!

    I wonder what you use for managing startup services since sysv-rc-conf does not work anymore, at least for some things now managed with upstart? (e.g. tftp)

    I have changed /etc/init/tftpd-hpa.conf to:
    start on runlevel [!12345]
    so that it will only start if I manually:
    /etc/init.d/tftpd-hpa start
    Which is what I want, but this does not seem like a best practice. Looked for some better solution or documentation, but have not found anything.

    ReplyDelete
  2. I think this is a great idea. I don't have servers like you do, but I'm soon to get one, and than I sure would like to know when and why it reboots. I would definitely use this. Some more settings and perhaps a nifty GUI (for KDE too) and it would kick ass!

    ReplyDelete
  3. This is really cool. I would definitely use it. Can I do this on my work computer as well? I rarely ever reboot it and I often access if from home. What do I need to do so that mail can deliver to external addresses like my personal email address? I think by default sending out mail is blocked but I dont know at what level that happens and how to enable it. It would be great if you could forward me to the right direction. Again thanks for this awesome utility!

    ReplyDelete
  4. Looks nice. But isn't asking for configuration information from debconf a bit against Ubuntu's general style?

    ReplyDelete
  5. As a new customer of unmanaged Linodes. This script is just what every Linode customer needs.

    ReplyDelete
  6. Dustin,

    Cool tool. Currently, I know that my server rebooted through logwatch when it shows me the entire dmesg upon a reboot.

    ReplyDelete
  7. Aras, just apt-get install bootmail and it should be ready to send email. All of the necessary tools are installed.

    :-Dustin

    ReplyDelete
  8. Amit,

    Yeah, logwatch is neat. To get this behavior out of bootmail, you'd simply 'echo /var/log/dmesg >> /etc/bootmail/logs' and it would email you dmesg too. Good idea ;-)

    :-Dustin

    ReplyDelete
  9. mbp,

    As far as I'm aware, it's only really frowned upon in packages that are installed by default in the debian-installer. Otherwise, debconf questions are very much encouraged to help make packages usable by default. In this case, knowing the email where to send bootmail output is absolutely essential for this package to work properly at all, which is why I've set the debconf priority to "high".

    Thanks,
    :-Dustin

    ReplyDelete
  10. Hi,

    I've installed bootmail on my ubuntu 11.04 server and works like a charm!. At first I didn't have the 'apt-add-repository' tool, but after googling I found out I had to install the following:

    sudo apt-get install python-software-properties


    Thanks for this nice tool!

    ReplyDelete
  11. Hi Dustin,

    Thanks for this, I've been looking for this sort utility for quite some time.

    I just installed it on two servers each running 11.04 or 10.04. If I run `sudo bootmail`, I do indeed get the email. However, when I reboot, I don't get the email. Do I have to do something to turn on this setting??? Thanks.

    ReplyDelete
  12. Regarding my previous inquiry, I just had to set up my mail for the root user. I only had it set up for me before. Thanks for the useful utility!

    ReplyDelete
  13. @Vinh probably your smtp server (exim4, postfix,etc) is configured to only send mails locally. Just run:

    sudo dpkg-reconfigure exim4-config

    and reconfigure it.

    @Dustin another great tool, i am using it on all of my servers. Keep the good work!

    ReplyDelete
  14. I just upgraded my server from Lucid to Oneiric. Bootmail was working for me before. However, I'm not getting the bootmail after upgrade. I note that a manual run of bootmail does indeed send the email, just not at startup.

    $ sudo bootmail
    [sudo] password for vinh:
    gpg: WARNING: unsafe ownership on configuration file `/home/vinh/.gnupg/gpg.conf'
    gpg: WARNING: unsafe ownership on configuration file `/home/vinh/.gnupg/gpg.conf'
    gpg: WARNING: unsafe ownership on configuration file `/home/vinh/.gnupg/gpg.conf'

    ReplyDelete
  15. are there any plans to get this to other distros? Besides my many ubuntu servers, there are also centos servers on which I have to keep an eye on

    ReplyDelete
  16. Hi there!

    I have no intentions on maintaining bootmail for anything other than Ubuntu.

    Someone else is certainly welcome to package it for Debian, CentOS or other distros.

    Sorry! I just brew the beer. It's up to someone else to distribute it :-)

    Dustin

    ReplyDelete

Please do not use blog comments for support requests! Blog comments do not scale well to this effect.

Instead, please use Launchpad for Bugs and StackExchange for Questions.
* bugs.launchpad.net
* stackexchange.com

Thanks,
:-Dustin

Printfriendly