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 and used to manage processes, and people have asked to see them.

Here’s for starting Apache:

#$Id:,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

#$Id:,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.

Stalk me on social media