Skip to content

Instantly share code, notes, and snippets.

@taoalpha
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save taoalpha/c507f8931bd78fc54ed5 to your computer and use it in GitHub Desktop.

Select an option

Save taoalpha/c507f8931bd78fc54ed5 to your computer and use it in GitHub Desktop.
simple shell script which can restart mysql when your site down.
log=autocheck.log
nflag=`curl --connect-timeout 3 --max-time 2 "http://callmet.zzgary.info/link/" -o $log`
# change the grep text according to your condition.
err=$?
# get the error code.
flag=`cat $log | grep "Database Error" -c`
pflag=`cat $log | grep "502 Bad Gateway" -c`
#echo $err;
#echo $flag;
#echo $pflag;
if [ $flag -eq 0 ] && [ $err -ne 28 ] && [ $pflag -eq 0 ] && [ $err -ne 7 ]; then
# all good.
echo "running normal";
elif [ $flag -ne 0 ]; then
# mysql down.
service mysql restart
elif [ $err -eq 7 ]; then
# nginx down
service nginx restart
elif [ $pflag -ne 0 ]; then
#php down
service php5-fpm restart
else
# restart both
service php5-fpm restart
service nginx restart
service mysql restart
fi
echo > autocheck.log
# clear the log file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment