-
-
Save dayreiner/19661bfe5ad52fc34183 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
_DEBUG="on" | |
DEBUGFILE=/tmp/sentinel_failover.log | |
VIP='10.125.125.30' | |
MASTERIP=${6} | |
MASK='26' | |
IFACE='eth0' | |
MYIP=$(ip -4 -o addr show dev ${IFACE}| grep -v secondary| awk '{split($4,a,"/");print a[1]}') | |
DEBUG () { | |
if [ "$_DEBUG" = "on" ]; then | |
$@ | |
fi | |
} | |
#set -e | |
DEBUG date >> ${DEBUGFILE} | |
DEBUG echo $@ >> ${DEBUGFILE} | |
DEBUG echo "Master: ${MASTERIP} My IP: ${MYIP}" >> ${DEBUGFILE} | |
if [ ${MASTERIP} = ${MYIP} ]; then | |
if [ $(ip addr show ${IFACE} | grep ${VIP} | wc -l) = 0 ]; then | |
sudo /sbin/ip addr add ${VIP}/${MASK} dev ${IFACE} >> ${DEBUGFILE} 2>&1 | |
DEBUG echo "sudo /sbin/ip addr add ${VIP}/${MASK} dev ${IFACE}" >> ${DEBUGFILE} | |
sudo /usr/sbin/arping -q -c 3 -A ${VIP} -I ${IFACE} >> ${DEBUGFILE} 2>&1 | |
fi | |
exit 0 | |
else | |
if [ $(ip addr show ${IFACE} | grep ${VIP} | wc -l) != 0 ]; then | |
sudo /sbin/ip addr del ${VIP}/${MASK} dev ${IFACE} >> ${DEBUGFILE} 2>&1 | |
DEBUG echo "sudo /sbin/ip addr del ${VIP}/${MASK} dev ${IFACE}" >> ${DEBUGFILE} | |
fi | |
exit 0 | |
fi | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment