Try this from cron:
#!/usr/bin/perl
use Mail::Send;
use strict;
my $VERBOSE = 0;
if(@ARGV && $ARGV[0] eq "-v") {
$VERBOSE = 1;
shift;
}
my $OK = 0;
my $DEAD = -1;
my $RESTARTED = 1;
my $SER_PID = (@ARGV && $ARGV[0]) || "/var/run/ser.pid";
my $result = ser();
if($result != $OK) {
my $m = new Mail::Send;
my $subject = $ENV{HOSTNAME} . ": ";
$subject .= $result == $DEAD ? "FATAL SER ERROR " : "WARNING -
SER RESTARTED";
my $body = $result == $DEAD ? "ser did not start after
/etc/rc.d/ser restart" : "ser was not running, but was successfully
restarted with /etc/rc.d/ser/restart";
$m->subject($subject);
$m->to('root');
my $fh = $m->open;
print $fh $body;
$fh->close;
}
sub ser {
my $status = $OK;
if(! ser_running()) {
$status = $DEAD;
print "$0: ser not running ($SER_PID)\n" if($VERBOSE);
system("(/etc/rc.d/ser restart 2>&1) >/dev/null");
sleep 10;
if(ser_running()) {
print "$0: ser now running after restart\n"
if($VERBOSE);
$status = $RESTARTED;
}
} else {
print "$0: ser running ok - nothing to do\n" if($VERBOSE);
}
return $status;
}
sub ser_running {
if(! -e $SER_PID || ! -f $SER_PID) {
return 0;
} else {
open( SER , "< $SER_PID" ) ||
die "$0: failure opening: $SER_PID ($!)\n";
my $pid = <SER>;
chomp $pid;
if(kill 0, $pid) {
return 1;
} else {
return 0;
}
}
}