http://www.perlmonks.org?node_id=695027

A little script that checks to see if a site is up based on the response code; a response of 500 executes a shell script that kills and restarts the FastCGI processes whereas a response of 404 restarts the Web server. Oh, and keeps a little log.
#!/usr/bin/perl -w use strict; use WWW::Mechanize; use DateTime; my @urls = ( "http://mysite.net", "http://myothersite.org" ); # Command to execute the webrestart shell script my $fcgi_restart = "./webrestart"; # Command to restart Lighttpd (may vary by distro) my $lighttpd_restart = "/etc/init.d/lighttpd restart"; # Set the current date and time for the log file using DateTime from C +PAN my $date_time = DateTime->now; # Set path to the log file you want to use my $log = '/path/to/log.txt'; # Loop through each of your sites foreach my $site (@urls) { # Get the Status using WWW::Mechanize from CPAN my $mech = WWW::Mechanize->new(); $mech->get( $site ); my $status = $mech->status($site); # If there is a server error, we will restart all the FastCGI pro +cesses. if ($status == '500') { system $fcgi_restart; # Log this site failed and when open(DAT,">>$log") || die("Cannot Open File"); print DAT "$site || $status || $date_time \n"; close DAT; } # If the site was not found, we will restart Lighttpd. elsif ($status == '404') { system $lighttpd_restart; } } # Log that the sites were checked and when open(DAT,">>$log") || die("Cannot Open File"); print DAT "Sites checked $date_time \n"; close DAT;
External shell script to kill and restart all FastCGI processes
# Thanks Russell Jurney <rjurney (at) lucision.com> pkill -f fcgi pkill -f fcgi-pm pkill -9 -f fcgi pkill -9 -f fcgi-pm /path/to/mysite.net/fastcgi.pl -l /tmp/mysite.socket -n 3 -d /path/to/myothersite.com/fastcgi.pl -l /tmp/mysite.socket -n 3 -d