Skip to content

Instantly share code, notes, and snippets.

@aaronbbrown
Created December 4, 2011 00:28
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/1428617 to your computer and use it in GitHub Desktop.
Save aaronbbrown/1428617 to your computer and use it in GitHub Desktop.
Restart slave when it lags too much
#!/bin/bash
U=user
P=pass
MYSQLCMD="mysql -u $U -p$P -BN -e"
while : ; do
LAG=$($MYSQLCMD "select now()-ts as behind_by from maatkit.heartbeat limit 1;" | awk -F. '{print $1}')
echo "$(date) $LAG"
if [[ $LAG -gt 120 ]]; then
echo "$(date) lag is higher than 120, restarting slave"
mysqladmin -u $U -p$P stop
mysqladmin -u $U -p$P start
fi
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment