Monitoring subversion with monit
In spite of the Orwellian title, this is about monitoring the Subversion revision control system using Monit on a Linux server. I recently set up Monit to monitor services running a server. It's pretty neat - you can tell it what services to listen to, how to decide if they are responsive, and what to do in the event that they're not. I found a bunch of simple config scripts for most of the services I wanted to monitor on their wiki, but couldn't find a cut-and-paste solution for monitoring Subversion, so I wrote my own.
This obviously requires that you have Monit and Subversion (easy with apt-get):
$ apt-get install subversion monitSubversion annoyingly doesn't come with an init script (at least not from the Ubuntu repositories). From the Ubuntu help pages about Subversion, I found a handy init script to easily control svnserve and have it start on boot (see the author's blog post to help get Subversion set up properly and to load the server on boot). However, the init script doesn't tell svnserve to create a PID file when it executes. One easy way monitor services running on your system is by having Monit use a PID file to check if that service is running, so I modified the init script a bit to have svnserve generate a pid file. You can find my version here.
Now for the Monit config script for svnserve:
check process svnserve with pidfile /var/run/svnserve.pid
start program = "/etc/init.d/svnserve start"
stop program = "/etc/init.d/svnserve stop"
if failed host localhost port 3690 then restart
if 5 restarts within 5 cycles then timeout
depends on svnserve_bin
depends on svnserve_rc
check file svnserve_bin with path /usr/bin/svnserve
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
check file svnserve_rc with path /etc/init.d/svnserve
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitorNow if for some reason my Subversion server goes down or quits working, Monit will try to restart the service and (based on my main Monit config), I will get an email alert. Piece of cake.




Post new comment