Squid Monitoring Script

From: Chris Owen <listsonly@dont-contact.us>
Date: Sun, 21 Jun 1998 18:26:10 -0500 (CDT)

I went looking for a squid monitoring script today and after not really
finding anything I realized that I'd spent more time looking than it would
have taken to just write one ;-]

Below is what I plan on using. I'd be interested in any other scripts out
there that might be better or any feedback on this script.

The basic idea here is to run this from cron say every 10 minutes. The
script:

Checks to see if the squid process is running, if so exit
Otherwise restart squid
Wait 30 seconds, check again
If now running, email a report
If not running, restart machine, email a report
If after restart script fails again give up and send another email

What I'm wondering is if there is anything else that can be done if a
restart and a reboot don't work. I've got a similar script for listproc
for instance that cleans up so files and tries to restart after that.
I've never really had any problems with squid so I haven't had any
experience on what goes wrong.

Anyway here is the script, I'd appreciate any feedback.

Chris

[-- snip --]

#!/usr/bin/perl

#
# 6/21/98 - Chris Owen: Automatically Restart Squid if not running!
#
# owenc@gcnet.com
#

$PATH = "/root/scripts/checksquid";

# test if running
$_ = `ps auxw | grep squid`;
$* = 1; # make sure we check across newline boundaries

# if it is running hopefully every is ok so remove any state files and
exit
if (/squid \-Ds/) {
  `rm /tmp/squid.restarted` if (-f "/tmp/squid.restarted");
  `rm /tmp/squid.rebooted` if (-f "/tmp/squid.rebooted");
  `date >> /tmp/checksquid.log`;
  exit;
  }

# well it isn't there, try to restart it normally
system ("/etc/rc.d/init.d/squid start");

# wait 30 seconds to let squid start up
sleep 30;

# test and hopefully it restarted
# send email anyway because this should not be happening
$_ = `ps auxw | grep squid`;
if (/squid \-Ds/) {
   system ("mail -s \"squid has been automatically restarted\" staff\@gcnet.com <$PATH/restart >/dev/null");
   exit;
}

# this is bad, we've got a real problem if we get here

# make sure we haven't been here before, no reason to just keep rebooting
if (-f "/tmp/squid.rebooted") {
  system ("mail -s \"COULD NOT AUTOMATICALLY RESTART SQUID!\" owenc\@gcnet.com <$PATH/fail >/dev/null");
  exit;
  }

# nothing to lose at this point so try restarting machine
system ("mail -s \"SQUID MACHINE HAD TO BE REBOOTED\" owenc\@gcnet.com <$PATH/reboot >/dev/null");
`touch /tmp/squid.rebooted`;
sleep 10; #just to make sure the email gets sent
`/sbin/shutdown -r now`;

exit;

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Chris Owen             ~  Lottery: A stupidity tax
PO Box 1985            ~  owenc@gcnet.com
Garden City, KS 67846  ~  http://www.gardencity.net/~owenc/
Voice: (316) 275-1900  ~  ftp://ftp.gardencity.net/pub/owenc/
Fax:   (316) 275-0313  ~  88 FA CF C6 65 23 63 C1  6E 80 AE 0B 51 C0 22 36
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Received on Sun Jun 21 1998 - 16:28:01 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:40:46 MST