Earlier I discussed using HAST to mirror a ZFS across two machines. I also discussed using devd with CARP interfaces, to run a script when a machine changes between master and backup. Now let’s glue these together to synchronize a ZFS switch with CARP state, and to run scripts when the system becomes the master or the backup.
The devd article referred to a script “carp-hast-switch.” That script was written by Freddie Cash. I took the script and added some stuff to make it more useful for my environment. My version of the script is available here. Set up HAST as per the first article. Set up CARP and devd as per the second article. Put this script in /usr/local/scripts/, and change the variables at the top to match your environment.
The critical additions for me were “master” and “slave” options. I want to execute scripts after the HAST failover completes, to start the programs that serve the data on that partition. These variables let you do that. I suspect that other people will want to have scripts that run before failover starts, but those should be easy to add.
I’d really like to see this sort of script included as an example in the FreeBSD documentation. The wiki document suggests using ucarp, but we have real CARP. And now that Will Andrews has made CARP a kernel module, there’s no reason to use ucarp.
I really thought this post would be longer, but the script pretty much speaks for itself. Ah, well.Stalk me on social media