#! /bin/sh # # lvsdr Start/Stop network configuration for LVS with Direct-Return # # chkconfig: 345 74 06 # description: just set some network parameters in case this host belongs to # a LVS cluster. We assume the cluster is managed by heartbeat and this # host may also run heartbeat. This script must be launched before heartbeat. # # Source function library. . /etc/init.d/functions # For RedHat like distros: # Get config. if [ -f /etc/sysconfig/network ]; then . /etc/sysconfig/network else echo $"Networking not configured - exiting" exit 1 fi # Check that networking is up. if [ "$NETWORKING" = "no" ]; then exit 0 fi # Our stuff starts here: prog="lvsdr" # You can change the Default Interface if it is not specified by IPaddr2: DFLT_INTERFACE=eth0 declare -a VIPS INTERFS # Try to determine the VIP and the INTERFACE if they are not set: if [ "$VIPS" = "" ]; then HA_INIT=/etc/init.d/heartbeat if [ -f $HA_INIT ]; then HA_DIR=`grep "^HA_DIR=" $HA_INIT 2>/dev/null` HA_DIR=`echo $HA_DIR | cut -d';' -f1 | cut -d'=' -f2` LINES=(`sed -r -n "/IPaddr2::.*ldirectord/s/.*IPaddr2::([^[:space:]]*).*/\1/p" $HA_DIR/haresources | tr -s '\t ' `) IND=0 while [ $IND -lt ${#LINES[@]} ]; do #echo ${LINES[$IND]} VIPS[$IND]=`echo ${LINES[$IND]} | cut -d/ -f1` INT=`echo ${LINES[$IND]} | cut -d/ -f3` if [ "$INT" != ${VIPS[$IND]} ]; then INTERFS[$IND]=$INT fi IND=$[ $IND + 1 ] done fi fi if [ ${#VIPS[@]} -eq 0 ]; then echo "Warning: could not determine VIP to handle in file $HA_DIR/haresources" exit 0 fi RETVAL=0 check_interface() { if [ -d /proc/sys/net/ipv4/conf/$INTERFACE ]; then return 0 fi echo "Interface $INTERFACE not present" return 1 } start() { echo -n $"Starting $prog: " IND=0 while [ $IND -lt ${#VIPS[@]} ]; do INTERFACE=${INTERFS[$IND]:-eth0} if check_interface $INTERFACE; then ip addr add ${VIPS[$IND]}/32 brd 255.255.255.255 dev lo 2>/dev/null echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/$INTERFACE/arp_announce fi IND=$[ $IND + 1 ] done success echo return $RETVAL } stop() { echo -n $"Stopping $prog: " IND=0 while [ $IND -lt ${#VIPS[@]} ]; do INTERFACE=${INTERFS[$IND]:-eth0} if check_interface $INTERFACE; then ip addr del ${VIPS[$IND]}/32 brd 255.255.255.255 dev lo 2>/dev/null echo 0 > /proc/sys/net/ipv4/conf/$INTERFACE/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/$INTERFACE/arp_announce fi IND=$[ $IND + 1 ] done success echo return $RETVAL } status() { ip addr show | grep "${VIPS[0]}.*lo$" >/dev/null 2>&1 if [ $? -eq 0 ]; then echo "$prog is running" else echo "$prog is not running" fi return 0 } restart() { stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status ;; restart|reload) restart ;; *) echo $"Usage: $0 {start|stop|status|restart|reload}" exit 1 esac exit $?