Date: Tue, 23 Jan 2001 14:27:09 -0500 From: "Dejvid Zaninovic" <dzaninov@mediaondemand.com> To: <hackers@FreeBSD.ORG> Subject: IP Address Overtaking Message-ID: <001701c08572$7d218a90$230aa8c0@newyork.mod>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?001701c08572$7d218a90$230aa8c0>