Skip to content

Instantly share code, notes, and snippets.

@rhoml
Last active August 29, 2015 14:01
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 rhoml/1c1165962a54cac0b44a to your computer and use it in GitHub Desktop.
Save rhoml/1c1165962a54cac0b44a to your computer and use it in GitHub Desktop.
Reconfigure script for sentinel to update twemproxy when certain redis instance fails.
#!/bin/bash
# <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
export PATH=/sbin:/usr/local/bin:$PATH
NUTCRACKER_CONF='/opt/nutcracker/conf/nutcracker.yml'
NUTCRACKER_PORT=22121
MASTER_NAME=$1
ROLE=$2
STATE=$3
FROM_IP=$4
FROM_PORT=$5
TO_IP=$6
TO_PORT=$7
if [ "$#" = "7" ]; then
# Modify nutcracker.yml file
sed -i s/${FROM_IP}:${FROM_PORT}/${TO_IP}:${TO_PORT}/g ${NUTCRACKER_CONF}
# Pause traffic on nutcracker while we restart
iptables -I INPUT -p tcp --dport ${NUTCRACKER_PORT} --syn -j DROP
# Restart nutcracker
/etc/init.d/nutcracker restart
# Resume traffic after restarting
iptables -D INPUT -p tcp --dport ${NUTCRACKER_PORT} --syn -j DROP
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment