Skip to content

Instantly share code, notes, and snippets.

@hgfischer
Created October 17, 2011 21:33
Show Gist options
  • Save hgfischer/1293888 to your computer and use it in GitHub Desktop.
Save hgfischer/1293888 to your computer and use it in GitHub Desktop.
Keepalived Notify-Redis
#!/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