How I installed monit as an upstart service

Upstart is Ubuntu’s replacement for /sbin/init, and Monit is a great little monitoring service that lets you do intelligent things when errors occur and servers fall over. But for some reason Monit is still installed as a System V init daemon. So I switched it over to use Upstart.

To be honest, most of the information on how to do this was an old post at Airblade Software: here. A couple of tweaks to match the updated version of upstart and it worked. So they deserve the credit. But for my future reference, and hopefully to help other people as well here are the very simple instructions:

sudo apt-get install monit
sudo /etc/init.d/monit stop
sudo update-rc.d -f monit remove
echo "start on runlevel [2345]" | sudo tee -a /etc/init/monit.conf
# ^^^ alternate option: start on startup
echo "stop on runlevel [06]" | sudo tee -a /etc/init/monit.conf
# ^^^ alternate option: stop on shutdown
echo "respawn" | sudo tee -a /etc/init/monit.conf
echo "script" | sudo tee -a /etc/init/monit.conf
echo "  exec /usr/bin/monit -Ic /etc/monit/monitrc" | sudo tee -a /etc/init/monit.conf
echo "end script" | sudo tee -a /etc/init/monit.conf
sudo chmod a+r /etc/init/monit.conf

Don’t forget to edit your monitrc file either! The best way to get started is by uncommenting and tweaking the default settings. For reference, I did this on Ubuntu 12.04 with upstart version 1.5 and monit version 5.3.2.

What do you think?