Hi
I have the following at the end of a service shutdown script used in part of an active-passive failover setup:
Code:
###
# Shutdown all primary Network Interfaces
# associated with failover
###
# get interface names based on IP's
# and shut them down to simulate loss of
# heartbeatd
PRIV_IP="10.0.4.81"
INT_IP="192.168.0.10"
PRIV_IF=`ifconfig |grep -B 1 ${PRIV_IP}| awk '{ printf ("%s\t" , $1) }'| awk '{ print $1 }'|tr -d ":"`
INT_IF=`ifconfig |grep -B 1 ${INT_IP}| awk '{ printf ("%s\t" , $1) }'| awk '{ print $1 }'|tr -d ":"`
ifconfig ${PRIV_IF} down
ifconfig ${INT_IF} down
exit 0
Essentially it uses the IP to obtain the name of the interface associated with that IP, and then shutdown the relevant interface (this simulates a loss of connection and instigates failover. I have another NIC that I am able to ssh into to make sure that the server remains in its failed state - i.e. the script does not shutdown the primary server). The
PRIV_IP, for example, is associated with
bond0. The output for
bond0 is the following:
Code:
bond0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 10.0.4.81 netmask 0xff000000 broadcast 10.255.255.255
inet x.x.x.x netmask xxxxxxxxxx broadcast x.x.x.x
ether 00:0d:93:9d:9e:8f
media: autoselect (1000baseT <full-duplex,flow-control>) status: active
supported media: autoselect
bond interfaces: en0 en1
Is there any way to make this more elegant/efficient?
Mike