Created
October 17, 2011 21:33
-
-
Save hgfischer/1293888 to your computer and use it in GitHub Desktop.
Keepalived Notify-Redis
This file contains 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 | |
MASTER_IP='111.22.33.44' | |
MASTER_PORT=6379 | |
if [ "$#" -lt "3" ] | |
then | |
exit | |
fi | |
function log() { | |
logger -i -s -p daemon.info $@ | |
} | |
log 'Connecting do Redis@localhost' | |
state=$3 | |
log "Changing to state $state" | |
sleep 5 | |
case "$state" in | |
'MASTER') | |
log 'Sending SLAVEOF NO ONE' | |
redis-cli SLAVEOF NO ONE | |
;; | |
'BACKUP') | |
log "Sending SLAVEOF $MASTER_IP $MASTER_PORT" | |
redis-cli SLAVEOF $MASTER_IP $MASTER_PORT | |
;; | |
'FAULT') | |
log 'Shutting down REDIS' | |
redis-cli SHUTDOWN | |
;; | |
*) | |
log "Unknown state $state" | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment