#!/bin/bash
. /etc/rc.d/init.d/functions
MPORT=`netstat -atnlp | grep 3306| wc -l`
MPROC=`ps ax | grep mysqld | grep -v mysqld | wc -l`
MSOCK=/var/lib/mysqld/mysql.sock
MPROG=mysqld
if [ $MPORT -ne 0 -a -S $MSOCK ];then
action "mysql db is running" /bin/true
else
/etc/init.d/mysqld start &> /dev/null
if [ $MPORT -ne 0 -a -S $MSOCK ];then
rm -fr $MSOCK
while true
do
killall $MPROG &> /dev/null
[ $? -ne 0 ] && break
sleep 1
done
/etc/init.d/mysqld start &> /dev null && MSTAT="success" || MSTAT="failure"
date >> /tmp/mysqllog
echo "mysql db is $MSTAT" >> /tmp/mysqllog
mail -s "mysql db is $MSTAT" root < /tmp/mysqllog
fi
fi