无法从cron作业重新启动mysql

我有一个问题,在几天后,MySQL(在Ubuntu 12.04上运行的所有最新的更新)都会死掉,所以把这个脚本放到每60秒以root身份运行的cron作业中。

一切工作,除了MySQL服务将不会重新启动,我已经尝试使用“服务MySQL重新启动”和“/ usr /斌/ mysqld”,他们也不工作。

我正在使用完整的path来重新启动命令,所以我不相信这是一个问题。 现在唯一的作用是用“重新启动”replace重新启动命令,这是非常丑陋的,我想避免它。

#!/bin/bash #Check if MySQL is up, if not then start it # mysql root/admin username MUSER="root" # mysql admin/root password MPASS="REMOVED" # mysql server hostname MHOST="localhost" #Shell script to start MySQL server ie path to MySQL daemon start/stop script. # Debain uses following script, need to setup this according to your UNIX/Linux/BSD OS. MSTART="/etc/init.d/mysql restart" # Email ID to send notification EMAILID="some@email.net" # path mysqladmin MADMIN="$(which mysqladmin)" MAILMESSAGE="/tmp/mysql.fail.$$" # see if MySQL server is alive or not $MADMIN -h $MHOST -u $MUSER -p${MPASS} ping 2>/dev/null 1>/dev/null if [ $? -ne 0 ]; then echo "" >$MAILMESSAGE echo "ALERT: MySQL Server is not responding to ping">>$MAILMESSAGE echo "Hostname: $(hostname)" >>$MAILMESSAGE echo "System Time: $(date)" >>$MAILMESSAGE # try to start mysql $MSTART>/dev/null # see if it is started or not o=$(ps cax | grep -c ' mysqld$') if [ $o -eq 1 ]; then sMess="MySQL server successfully restarted" else sMess="MySQL server FAILED to restart" fi # Email status too echo "Current Status: $sMess" >>$MAILMESSAGE echo "" >>$MAILMESSAGE echo "*** This email generated by $(basename $0) shell script ***" >>$MAILMESSAGE echo "*** Please don't reply this email, this is just notification email ***" >>$MAILMESSAGE # send email sendemail -o message-content-type=text -f some@email.net -t $EMAILID -u MySQL GURU ALARM -m < $MAILMESSAGE else # MySQL is running :) and do nothing : fi # remove file rm -f $MAILMESSAGE 

没有看到启动错误日志,几乎不可能诊断。

如果我不得不冒险猜测,这听起来很可能是错误的,这个过程可能无法从cron分配它需要的内存,但在通过交互式shell运行时不会受到限制。 MySQL日志会证实这一点,虽然是以非描述的方式。

此外,不要重新发明轮子半翘脚本,只是使用像monit认可的监测应用程序