Hi
> : I am thinking about the best and most secure way to start squid.
I have a really ugly hack!
Here it is:
(It's actually more elegant than it looks. Perl uses a resonable method
of checking if a program has died, so instead of having to poll to
check if squid is running - ie by running ps etc - it is automatically
restarted.)
BTW - I have only ever recieved mail if there is a problem that I
have created, and had to kill squid dead... (-9)
In the cache's crontab:
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * (/usr/local/bin/runcache &)
(You can effectively put it in every minute, though you might want to
re-write this in something like ash then, otherwise reloading perl could get
heavy. We currently have more than enough ram on the box, so it just caches
perl...)
And the file /usr/local/bin/runcache?
#!/usr/bin/perl
# (C) Oskar Pearson - Restarts the proxy, mails logs to us if there is a
# problem with it...
#If you send a kill -ABRT to the runcahce program, it will not restart auto-
#matically until you remove the file /tmp/dont.restart.squid
#once you do, it should either restart in 2 minutes, or you can do it
#yourself. Please note - this is only if you are really paranoid about
#the cache being down... squid doesn't die ;)
$SIG{'ABRT'} = 'handler';
#Last time, we got the ABRT signal
if(-e "/tmp/dont.restart.squid"){
exit(1);
}
#Squid is running, so, just because the restarter is down,
#we don't need to kill squid... rather that if it does die,
#it will be restarted by this... Then it is a child process.
if(-e "/tmp/squid.pid"){
exit(1);
}
while (1) {
$starttime = `/bin/date`;
chop $startime;
open(RUNNING,"/usr/local/proxy/bin/squid|");
@log = <RUNNING>;
@log = "";
$dietime = `/bin/date`;
chop $dietime;
open(SENDMAIL,"|/usr/sbin/sendmail -fnobody@is.co.za oskar@is.co.za"
);
print SENDMAIL "The cache died at $dietime, after starting at\n";
print SENDMAIL "$starttime\n";
print SENDMAIL "A tail of the logs follows:\n\n";
open(TAIL,"/usr/bin/tail -200 /usr/local/proxy/logs/cache.log|");
while (<TAIL>) {print SENDMAIL "$_";}
close(SENDMAIL);
sleep(2);
}
#Catches interrupts...
sub handler {
open(KILLED,">/tmp/dont.restart.squid");
print KILLED "Killed with -ABRT\n";
`/usr/sbin/chown squid.squid /tmp/dont.restart.squid`;
close(RUNNING);
exit(0);
}
Received on Tue Sep 10 1996 - 16:05:51 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:32:59 MST