Skip to content

Instantly share code, notes, and snippets.

@holly
Created November 30, 2014 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save holly/42ecbce38f0a7c07daa6 to your computer and use it in GitHub Desktop.
Save holly/42ecbce38f0a7c07daa6 to your computer and use it in GitHub Desktop.
redis-sentinel client-reconfig-script
#!/bin/sh
# The following arguments are passed to the script:
#
# <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
MASTER_IP=$6
VIP=172.17.0.101
NETMASK=16
IF=eth0
MY_IP=$(ip addr show dev $IF | grep "global $IF" | head -1 | sed -e "s/^.*inet \(.*\)\/$NETMASK .*$/\1/")
echo "master_ip:$MASTER_IP my_ip:$MY_IP"
if [ ${MASTER_IP} = ${MY_IP} ]; then
echo "add $VIP/$NETMASK"
sudo /usr/bin/ip addr add ${VIP}/${NETMASK} dev ${IF}
# clear arp cache
sudo /usr/bin/arping -q -c 3 -A ${VIP} -I ${IF}
else
echo "del $VIP/$NETMASK"
sudo /usr/bin/ip addr del ${VIP}/${NETMASK} dev ${IF}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment