List:General Discussion« Previous MessageNext Message »
From:Aaron Holtz Date:April 19 2000 2:42pm
Subject:Re: cron job to restart/monitor Mysqld
View as plain text  
Here is what I use - it does a mysqlping which I think determines if mysql
is up or not.  I suppose you can add the isamchk to your start/stop
script.  I run this every 2 minutes - that is why I have it check for a
'lock' file.  Rather than comment the cronjob out, I just touch a file
called 'lock' if I'm working on it and don't want the cronjob to restart
mysql if I have it down.


#!/bin/perl

$ENV{'PATH'} = '/bin:/usr/bin:/usr/ucb:/usr/etc';
$hostname = `/bin/hostname`; chop($hostname);
$admin = "person\@domain.com";
$mailprog = '/usr/lib/sendmail';

if ( -f "/usr/local/bin/lock" ) {
        exit(0);
}

@checkmysql = `mysqladmin ping 2>&1 > /dev/null`;

foreach $line ( @checkmysql ) {
        if ( ($line !~ /is alive/i) && (!$startflag) ) {
                system ( "/etc/rc.d/init.d/mysql stop 2>&1 > /dev/null" );
                sleep 5;
                system ( "/etc/rc.d/init.d/mysql start 2>&1 > /dev/null" );
                $startflag = 1;
                &SendEmail;
        }
}

sub SendEmail {

        open(MAIL, "|$mailprog -t") || die ( "Can't open $mailprog!");
        print MAIL "From: Mysql Daemon <mysql\@$hostname>\n";
        print MAIL "To: <$admin>\n";
        print MAIL "Subject: Mysql Daemon for $hostname not running.\n\n";
        foreach $line ( @checkmysql ) {
                print MAIL "$line";
        }
        close (MAIL);
 
}


--------------------------------------------------------------------------
Aaron Holtz
ComNet Inc.
UNIX Systems Administration/Network Operations
"It's not broken, it just lacks duct tape."
--------------------------------------------------------------------------


On Apr 19, Graeme B. Davis molded the electrons to say....

>hello,
>
>i was wondering if any has a script that can be run in CRON to monitor and
>start mysql if it dies.  an added bonus would be that it runs (my)isamchk
>if the server dies right after you start it, etc.
>
>Any suggestions?
>
>---
>this  is my current script, but it doesn't seem to work when run from
>CRON -- from the command line it works fine... ??
>
>#!/usr/local/bin/perl5
>print ("MySQL starter...\n");
>$date=`date`;
>chop($date);
>open (OUTFILE, ">>/home/appsweb/bin/check.log");
>if (`/usr/ucb/ps -ax | grep "safe_mysqld" | grep -v grep`)
>{
>        print OUTFILE ("$date : MySQL up...\n");
>}
>else
>{
>        print OUTFILE ("$date : MySQL down... restarting now...\n");
>        system("cd /home/appsweb/mysql;
>bin/safe_mysqld --log=/home/appsweb/mysql/log &");
>}
>
>
>
>-- 
>---------------------------------------------------------------------
>Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
>posting. To request this thread, e-mail mysql-thread34635@stripped
>
>To unsubscribe, send a message to:
>    <mysql-unsubscribe-aholtz=bright.net@stripped>
>

Thread
mm.mysql.jdbc-2.0pre5 Date HelpBob Garvey19 Apr
  • cron job to restart/monitor MysqldGraeme B. Davis19 Apr
    • Re: cron job to restart/monitor MysqldAaron Holtz19 Apr
  • Re: mm.mysql.jdbc-2.0pre5 Date HelpSteve Ruby19 Apr