perl -e'sleep' httpd And your code will not detect that httpd is gone.
Besides that, your code only notices when a process is gone. Far more often, in my experience, processes are still there, but don't work properly. So instead, test the functionality. For example, I use this hack to restart my apache when needed:
Cron runs this every minute and it arranges for me to get mail when Apache was restarted (because the init scripts have output). As a nice side effect, this way I get lots of mail when the nameserver is broken :)#!/usr/bin/perl use strict; use LWP::Simple; exit 0 if -e "/etc/nouptest"; eval { local $SIG{ALRM} = sub { die "Alarm\n" }; alarm 10; my $p = get 'http://uptest.convolution.nl/'; $p =~ /xyzzy/ or die "Down\n"; alarm 0; }; if ($@) { if ($@ =~ /Alarm|Down/) { system qw[/etc/init.d/apache stop]; sleep 3; system qw[killall -9 apache]; sleep 3; system qw[/etc/init.d/apache start]; } }
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
In reply to Re: intelli-monitor.pl
by Juerd
in thread intelli-monitor.pl
by biosysadmin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |