Skip to content

Instantly share code, notes, and snippets.

@uncelvel
Forked from holly/redis-sentinel-failover.sh
Created July 12, 2022 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uncelvel/7cbbd01d0ee848a6eb8ea764ef74bead to your computer and use it in GitHub Desktop.
Save uncelvel/7cbbd01d0ee848a6eb8ea764ef74bead 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