Skip to content

Instantly share code, notes, and snippets.

@aaronbbrown
Created December 4, 2011 00:36
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 aaronbbrown/1428638 to your computer and use it in GitHub Desktop.
Save aaronbbrown/1428638 to your computer and use it in GitHub Desktop.
Restart slave if the binary log position doesn't change
#!/bin/bash
U=user
P=pass
MYSQLCMD="mysql -u $U -p$P -e"
SECS=60
OLDLOGPOS=1
while : ; do
LOGPOS=$($MYSQLCMD "SHOW SLAVE STATUS\G" | grep Exec_Master_Log_Pos | awk '{print $2}')
echo "$(date) pos: $LOGPOS old pos: $OLDLOGPOS"
if [[ $OLDLOGPOS -eq $LOGPOS ]]; then
echo "$(date) binlog position has not moved in $SECS seconds. Restarting slave..."
mysqladmin -u $U -p$P stop-slave
mysqladmin -u $U -p$P start-slave
fi
OLDLOGPOS=$LOGPOS
sleep $SECS
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment