process management with CARP/HAST failover

I’ve previously written about using HAST to replicate a ZFS between servers, using CARP devd events to trigger userland changes, and combining them to automate ZFS failover.  The scripts reference a master-process.sh and slave-process.sh used to manage processes, and people have asked to see them.

Here’s master-process.sh for starting Apache:

#!/bin/sh
#$Id: master-process.sh,v 1.2 2010/08/18 16:06:50 root Exp root $

logger -p local0.debug -t failover "I am Lord and Master"
/usr/local/etc/rc.d/apache22 onestart
logger -p local0.debug -t failover "started Apache"

And here’s slave-process.sh:

#!/bin/sh
#$Id: slave-process.sh,v 1.2 2010/08/18 16:06:50 root Exp $

/usr/local/etc/rc.d/apache22 onestop
logger -p local0.debug -t failover "shot apache"

I wanted to use FreeBSD’s built-in rc.d functions, but you can’t enable the software in /etc/rc.conf.  I don’t want the backup to start Apache at boot, only when it becomes master.  That’s exactly what onestart and onestop are intended for.

Note that HAST now has hooks for executing commands on certain events, such as becoming primary or backup.  I believe that those hooks will give us better control over processes, but I’m waiting for some MFCs before testing them.  I expect that those hooks will let me replace this entire process with something more reliable, but that’ll have to wait for another day.