From owner-freebsd-hackers Tue Jan 23 11:29:10 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from nyapp002.mediaondemand.com (mailhost.mediaondemand.com [208.184.36.78]) by hub.freebsd.org (Postfix) with ESMTP id BFF2F37B402 for ; Tue, 23 Jan 2001 11:28:48 -0800 (PST) Received: from nywst536 (nywst536.newyork.mod [192.168.10.35]) by nyapp002.mediaondemand.com (8.11.2/8.11.2) with SMTP id f0NJSin22151 for ; Tue, 23 Jan 2001 14:28:48 -0500 (EST) Message-ID: <001701c08572$7d218a90$230aa8c0@newyork.mod> From: "Dejvid Zaninovic" To: Subject: IP Address Overtaking Date: Tue, 23 Jan 2001 14:27:09 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I could not find any non-commercial IP Address overtaking solution for FreeBSD so I wrote this simple shell script. If you find it useful you can use it. ----------- #!/usr/local/bin/ksh # # Node v0.01 # # purpose: # - very simple ip address overtaking for FreeBSD systems # - can be used as simple apache clustering solution if used # with mod_backhand # # tested to work on: # - FreeBSD v4.1.1 # - pdksh v5.2.14 # - fping v2.2b1 # # command line arguments: # - node_name: resolvable name of the virtual node # # instructions: # - configure config section in the script # - run the same scipt on two or more cluster nodes using nohup # - for more virtual nodes run same script many times # # signals: # - send INT or TERM signal to stop the virtual node # - send HUP signal to switch virtual node to another node, # if another node don't take over the virtual node in 5 seconds # virtual node is switched back # # versions: # # v0.01 - 01.19.2001 - Dejvid Zaninovic (dzaninov1@icqmail.com) # - initial version # # config section NETWORK_INTERFACE=xl0 TMPDIR=/tmp # command line arguments SCRIPT_NAME=$0 NODE_ADDRESS=$1 # global vars init NODE_ETHER=$(ifconfig $NETWORK_INTERFACE | grep ether | cut -d" " -f2) LOCKFILE=$TMPDIR/$SCRIPT_NAME.$NODE_ADDRESS.lock MASTER=false # functions usage() { print -u2 "usage: $SCRIPT_NAME node_name" exit 1 } node_up() { print $SCRIPT_NAME: $NODE_ADDRESS: up ifconfig $NETWORK_INTERFACE alias $NODE_ADDRESS netmask 0xffffffff arp -S $NODE_ADDRESS $NODE_ETHER pub > /dev/null 2>&1 } node_down() { if $MASTER then print $SCRIPT_NAME: $NODE_ADDRESS: down ifconfig $NETWORK_INTERFACE -alias $NODE_ADDRESS netmask 0xffffffff arp -d $NODE_ADDRESS > /dev/null 2>&1 route delete $NODE_ADDRESS > /dev/null 2>&1 fi } node_check() { fping -q $NODE_ADDRESS } node_kill() { node_down rm $LOCKFILE print $SCRIPT_NAME: $NODE_ADDRESS: exit exit 0 } node_switch() { print $SCRIPT_NAME: $NODE_ADDRESS: switch node_down sleep 5 } # main trap node_kill INT TERM trap node_switch HUP if [[ $# -ne 1 ]] then usage fi if [[ -f $LOCKFILE ]] then print -u2 "$SCRIPT_NAME: $NODE_ADDRESS node is already running" exit 1 fi touch $LOCKFILE print $SCRIPT_NAME: $NODE_ADDRESS: started while true do node_check if [[ $? -ne 0 ]] then MASTER=true node_up fi sleep 1 done To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message