Skip to content

Instantly share code, notes, and snippets.

@silenius
Last active August 17, 2016 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silenius/7f6ee8030eb6b923affb655a259bfef7 to your computer and use it in GitHub Desktop.
Save silenius/7f6ee8030eb6b923affb655a259bfef7 to your computer and use it in GitHub Desktop.
#!/bin/sh
log_name="filer"
log_prio="user.notice"
flog () {
logger -p "$log_prio" -t "$log_name" "$1"
}
boottime=$(sysctl -n kern.boottime | awk '{print $4}' | tr -dc 0-9)
now=$(date +%s)
delta=$(($now-$boottime))
if [ $delta -lt 180 -o -f /root/scripts/NO_FAILOVER ] ; then
flog "Failover script skipped (delta: $delta)"
exit
else
flog "Running failover script (delta: $delta)"
fi
case "$1" in
MASTER)
flog "Shutting down the replication interface"
ifconfig bge1 down
sysrc ifconfig_bge1="down"
# Backup is the new master
flog "Adapting advskew on the main interface"
sysrc ifconfig_bge0_alias0="inet vhid 54 advskew 10 pass xxx alias 192.168.10.15/32"
ifconfig bge0 vhid 54 advskew 10
flog "Shutting down the CTLD daemon"
sysrc ctld_enable="NO"
service ctld stop
while pgrep -u root ctld > /dev/null ; do
sleep 0.01
done
flog "Import data zpool"
zpool import -f -o cachefile=none data
;;
BACKUP)
flog "MASTER -> BACKUP"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment