I noticed that if I reboot a server that is the MASTER, the carp0 on the BACKUP box goes into MASTER mode and stays that way -- even when the real master machine has finished rebooting. Is this a desired trait to prevent CARP from switching IPs out of control?

Any how, I wrote a cronjob that runs once an hour on the slave. If if finds itself in the MASTER mode on a carp device, it up/down's the interface to get it back into the BACKUP mode.

Rudy




#!/bin/sh
# ------------------------------------------------------------------------------
# should_be_backup_carp.sh
# ------------------------------------------------------------------------------
# Check to make sure a carp device is in the backup state.
# Run this as an hourly CRON on the 'backup' machine.
#
# If the Backup machine is found in the 'MASTER' state, this script will cycle # the CARP device in an attempt to let the other device regain MASTER status.
# (for some reason, when the MASTER reboots, it does not reassert itself as
#  the MASTER on my system.)
#
# If you accidentally install this script on the MASTER server, you will get
# some not so good results.  :)
#
# THIS SOFTWARE IS PROVIDED BY Rudy ``AS IS'' AND WARRANTIES ARE DISCLAIMED.
# Rudy Rucker, Jr. -  2007

# Usage:
# Check carp0 (default) only:
#       0 * * * * /path/should_be_backup_carp.sh
# Check multiple devices:
#       0 * * * * /path/should_be_backup_carp.sh carp0 carp2 ...

# ------------------------------------------------------------------------------

if [ -n "$1" ]; then
        for D in $@; do
                _DEV=$D
                export _DEV
                $0
        done
        exit;
fi

DEV=${_DEV:=carp0}
#DEBUG=YES

STATE=`/sbin/ifconfig ${DEV:?"Error you must define a DEV"} 2> /dev/null | /usr/bin/grep vhid | /usr/bin/awk '{print $2}'`
STATE=${STATE:?"Error finding state for $DEV."}

if [ $STATE = 'MASTER' ]; then
        
        echo "${HOST:=`/bin/hostname`} is $STATE on $DEV."
echo "This script is going to cycle interface in attempt to relinquish MASTER status."
        echo "If this is not desired on $HOST, remove $0 from the crontab."
        echo
        echo "IFCONFIG before cylce:"
        /sbin/ifconfig $DEV
        /sbin/ifconfig $DEV down;
        sleep 3;
        echo
        echo "IFCONFIG during cylce:"
        /sbin/ifconfig $DEV
        /sbin/ifconfig $DEV up;
        sleep 3;
        echo
        echo "IFCONFIG after cylce:"
        /sbin/ifconfig $DEV
elif  [ $STATE != 'BACKUP' ]; then
        echo "Something is ill configured with $0"
        echo "${HOST:=`/bin/hostname`} is $STATE on $DEV."
        echo
        echo "I don't know what the state '$STATE' is all about."
elif [ -n "$DEBUG" ]; then
        echo "${HOST:=`/bin/hostname`} is $STATE on $DEV."
fi



_______________________________________________
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to