Last active
August 24, 2016 10:48
-
-
Save rpong/5c0f875ef76bace1149baa504d509b98 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/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