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>
>