Skip to content

Instantly share code, notes, and snippets.

@rpong
Last active August 24, 2016 10:48
Show Gist options
  • Save rpong/5c0f875ef76bace1149baa504d509b98 to your computer and use it in GitHub Desktop.
Save rpong/5c0f875ef76bace1149baa504d509b98 to your computer and use it in GitHub Desktop.
#!/bin/bash
#Redis Servers
array=( cache2 cache1 cache3 )
#output file
outputConfig='/config/redis.json'
function outputRedisConfig {
echo "{
\"RedisServers\": {
\"frontend\": {
\"uri\": \"tcp://$1:6379\",
\"timeout\": 5
},
\"backend\": {
\"uri\": \"tcp://$1:6379\",
\"timeout\": 5
}
}
}" > $outputConfig
}
currentMaster='';
if [ -f /var/log/lastRedisMaster ]; then
currentMaster=$(cat /var/log/lastRedisMaster)
fi
for i in "${array[@]}"
do
resp=$(redis-cli -h $i info | grep role:master)
if [ $resp ];
then
if [ "$currentMaster" != "$i" ];
then
outputRedisConfig $i
echo "$i" > /var/log/lastRedisMaster
service apache2 restart
break;
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment