Created
April 21, 2023 06:53
-
-
Save tykling/1d243e8a359f6f84f81c32c5239be87c to your computer and use it in GitHub Desktop.
FreeBSD rc.d script to switch CARP MASTER vhids to BACKUP state before shutdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# $FreeBSD$ | |
# | |
# PROVIDE: carpstop | |
# REQUIRE: securelevel | |
# KEYWORDS: nostart shutdown | |
. /etc/rc.subr | |
name="carpstop" | |
desc="Switch CARP vhid in MASTER state to BACKUP state. Run as the first thing when shutdown is initiated." | |
start_cmd=":" | |
stop_cmd="switch_carp_vhids_to_BACKUP" | |
rcvar="carpstop_enable" | |
switch_carp_vhids_to_BACKUP() | |
{ | |
for INTERFACE in $(ifconfig -l); do | |
if /sbin/ifconfig "${INTERFACE}" | grep -q "carp: MASTER vhid" ; then | |
/sbin/ifconfig $INTERFACE | while read -r LINE; do | |
if echo "$LINE" | grep -q "^carp: "; then | |
VHID=$(echo $LINE | cut -c 19- | cut -d " " -f 1) | |
logger -t carpstop "found CARP MASTER vhid ${VHID} on interface ${INTERFACE} - switching vhid to state BACKUP..." | |
/sbin/ifconfig ${INTERFACE} vhid ${VHID} state BACKUP | |
fi | |
done | |
fi | |
done | |
} | |
load_rc_config $name | |
run_rc_command "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment