Skip to content

Instantly share code, notes, and snippets.

@UserAd
Created February 12, 2015 10:40
Show Gist options
  • Save UserAd/236de9382b01940fbec3 to your computer and use it in GitHub Desktop.
Save UserAd/236de9382b01940fbec3 to your computer and use it in GitHub Desktop.
#!/bin/bash
real_lag=`mysql --defaults-file=/etc/mysql/debian.cnf -B -N -e "SELECT now()-timestamp AS replication_lag from tel_p.heartbeat;"`
seconds=`mysql --defaults-file=/etc/mysql/debian.cnf -e "SHOW SLAVE STATUS\G" | grep "Seconds_Behind_Master" | awk -F ": " {'print $2'}`
if [ "$real_lag" -gt "100" ]
then
logger "lag more than 100"
if [ "$seconds" -eq "0" ]
then
logger "Replication stopped. Restarting..."
mysqladmin --defaults-file=/etc/mysql/debian.cnf stop-slave
mysqladmin --defaults-file=/etc/mysql/debian.cnf start-slave
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment