MySQL faulty restart
Jump to navigation
Jump to search
Kai niekas nebepadeda, tuomet padeda šis scriptas. AutoStart/Recovery etc...
#!/bin/bash
PROC="mysqld"
COMD="/etc/init.d/mysqld start"
MAIL="justinas@eofnet.lt"
LOG="/var/log/check_mysql.log"
echo -n "Checking if mysql service is running.. "
if [[ -z $(ps -ef |grep -v grep |grep $PROC) ]]
then
echo "[Dead]"
echo "Restarting..."
killall -9 mysqld
echo "`date` - $PROC neveikia, restartuojame" >> $LOG
sed -i '/innodb_force_recovery/s/^#//g' /etc/my.cnf
$COMD
sed -i '/innodb_force_recovery/s/^/#/g' /etc/my.cnf
[ $? -eq "0" ] && echo "Process $COMD restart complete!" || echo "`hostname` - process - $PROC - unable to sart" | mail -n -s "Server status `hostname`" $MAIL && echo "`date` - Perkrovimas $PROC nepavyko" >> $LOG
mysqlcheck -A --auto-repair
else
echo "[Running]"
if tail -n1 /var/log/mysqld.log |grep -q "is marked as crashed and should be repaired"; then mysqlcheck -A --auto-repair&& echo "Fix to mysql applied" >> /var/log/mysqld.log; else echo "Log file seems to be ok"; fi
fi