From owner-freebsd-net@FreeBSD.ORG Tue Jun 12 23:08:52 2007 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B175D16A469 for ; Tue, 12 Jun 2007 23:08:52 +0000 (UTC) (envelope-from crapsh@monkeybrains.net) Received: from mail.monkeybrains.net (mail1.monkeybrains.net [208.69.40.8]) by mx1.freebsd.org (Postfix) with ESMTP id 850A913C45E for ; Tue, 12 Jun 2007 23:08:52 +0000 (UTC) (envelope-from crapsh@monkeybrains.net) Received: from monchichi.monkeybrains.net (adsl-75-36-247-158.dsl.pltn13.sbcglobal.net [75.36.247.158]) (authenticated bits=0) by mail.monkeybrains.net (8.13.7/8.13.7) with ESMTP id l5CMinFC092919 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 12 Jun 2007 15:44:49 -0700 (PDT) (envelope-from crapsh@monkeybrains.net) Message-ID: <466F21DA.20001@monkeybrains.net> Date: Tue, 12 Jun 2007 15:44:42 -0700 From: Rudy Rucker User-Agent: Thunderbird 2.0.0.0 (X11/20070513) MIME-Version: 1.0 To: freebsd-net@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV version 0.90.2, clamav-milter version 0.90.2 on mail.monkeybrains.net X-Virus-Status: Clean Subject: CARP on backup doesn't relinquish MASTER X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jun 2007 23:08:52 -0000 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