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

In reply to Keep FastCGI Processes Up and Running by SouthFulcrum

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.