This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Help...MYSQL crashing once per day
#12
RE: Help...MYSQL crashing once per day
Here is the bash script I created for my server. In case anyone else comes across this thread and would like to use my script for checking mysql and restarting. This is for Ubuntu with Sentora, but I'm sure it will work for most linux distributions (you may need to make some changes)

I added this line in crontab -e to run this script every 10 minutes
*/10 * * * * /bin/sh /home/root/scripts/mysql-service-check.sh >/dev/null 2>&1

UP=$(pgrep mysql | wc -l)
RFILE="/home/root/scripts/mysql-service-check.txt"
FFILE="/home/root/scripts/mysql-failure-log.txt"
NOW=$(date)
LOAD=$(uptime)

if [ $UP -eq 0 ]
then
#echo
"MySQL is down"
sudo service mysql start
echo "$NOW" >> $FFILE
echo "Subject: SERVER ALERT - Mysql Server was Down" > $RFILE
echo "The mysql server on your server was found to be down by our monitoring script on $NOW. The site was down for a maximum of 10 minutes. Crash logged in mysql-failure-log.txt" >> $RFILE
echo "" >> $RFILE
echo "This email should be proof that the services have been restored and the site is up and running. However, you should also confirm by going here: www.yoursite.com." >> $RFILE
echo "" >> $RFILE
echo "- YOUR SCRIPT MONKEY" >> $RFILE
echo "" >> $RFILE
echo "" >> $RFILE
echo "DIAGNOSTICS:" >> $RFILE
echo "$LOAD" >> $RFILE
echo "" >> $RFILE
echo "Syslog Error Log:" >> $RFILE
tail -100 /var/log/syslog | grep mysql >> $RFILE
echo "" >> $RFILE
echo "" >> $RFILE
echo "" >> $RFILE
echo "" >> $RFILE
echo "Mysql Error Log:" >> $RFILE
tail -100 /var/log/mysql/error.log >> $RFILE
/usr/sbin/sendmail you@youremail.com < $RFILE
fi


Hope this helps someone else. This script works perfectly to get things back up and running quickly and automatically, the most important thing. I would think Sentora should have something like this built in as mysql is critical and a down server means NO websites. But anyway, this script does the job. Now, I need to find out why mysql is crashing in the first place.
Reply
Thanks given by:


Messages In This Thread
RE: Help...MYSQL crashing once per day - by Me.B - 05-02-2015, 05:40 PM
RE: Help...MYSQL crashing once per day - by Me.B - 05-03-2015, 01:06 AM
RE: Help...MYSQL crashing once per day - by Me.B - 05-03-2015, 02:02 AM
RE: Help...MYSQL crashing once per day - by americanninja - 05-08-2015, 12:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
MySQL Database user prefix MosleyCale 1 5 ,011 10-17-2020, 09:11 PM
Last Post: Ron-e
Senator crash problem with mysql provokas 3 9 ,759 08-20-2020, 04:11 AM
Last Post: Your Creator
MySQL remote access... pixelbat 11 38 ,415 05-02-2020, 07:40 PM
Last Post: upendra.sahu1990@gmail.com

Forum Jump:


Users browsing this thread: 1 Guest(s)