[NTLUG:Discuss] Service Watchdog Script
Brian Koontz
brian at pongonova.net
Mon Oct 5 13:49:10 CDT 2009
On Mon, Oct 05, 2009 at 10:03:30AM -0700, CoryC wrote:
> Does anybody have an example of a service watchdog script that they
> are willing to share? All of the examples I'm finding on the
> Internet only work if the service uses a port but not all of the
> services I want to monitor use a port (Snort, arpwatch, etc.). I'd
> like for it to be able to e-mail me when one of those services are
> down and possibly even try to restart it. I'm using CentOS 5.3.
This works for me, took about 5 minutes to throw together. Replace
the parts you need. (The latest version of SpamAssassin's spamd
daemon is rather buggy, just in case you're wondering.)
I put it in crontab and have it e-mail me the output.
#! /usr/bin/perl
# monitorSpamd.pl -- Monitor spamd and respawn if necessary
#
#####################################################################
use strict;
my $found = 0;
my @results = `ps ax | grep spamd`;
foreach(@results)
{
if(/\/usr\/bin\/spamd/)
{
$found = 1;
}
}
if(!$found)
{
print "Restarting spamd...";
system("/usr/bin/spamd -r /var/log/spamd/spamd.pid -d");
print "...done!";
}
--Brian
More information about the Discuss
mailing list