And He Shall Rise Again and Walk Among You

Script I.2.3: Resurrecting a Dead Server

Restart a dead local server.

 #!/usr/local/bin/perl
 # script: webLazarus
 
 use LWP::Simple;
 use constant URL       => 'http://presto.capricorn.com/';
 use constant APACHECTL => '/usr/local/apache/bin/apachectl';
 $MAIL                  =  '/usr/sbin/sendmail';
 $MAIL_FLAGS            =  '-t -oi';
 $WEBMASTER             =  'lstein@prego.capricorn.com';
 
 head(URL) || resurrect();
 
 sub resurrect {
     open (STDOUT,"| $MAIL $MAIL_FLAGS") || die "mail: $!";
     select STDOUT; $| = 1;
     open (STDERR,">&STDOUT");
 
     my $date = localtime();
     print <<END;
 To: $WEBMASTER
 From: The Watchful Web Server Monitor <nobody>
 Subject: Web server is down
 
 I tried to call the Web server at $date but there was
 no answer.  I am going to try to resurrect it now:
 
 Mumble, mumble, mumble, shazzzzammmm!
 
 END
     ;
 
     system APACHECTL,'restart';
     
     print <<END;
 
 That's the best I could do.  Hope it helped.
 
 Worshipfully yours,
 
 The Web Monitor
 END
     close STDERR;
     close STDOUT;
 }

What You Hope To See

 Date: Sat, 4 Jul 1998 14:55:38 -0400
 To: lstein@prego.capricorn.com
 Subject: Web server is down

 I tried to call the Web server at Sat Jul  4 14:55:37 1998 but there was
 no answer.  I am going to try to resurrect it now:

 Mumble, mumble, mumble, shazzzzammmm!

 /usr/local/apache/bin/apachectl restart: httpd not running, trying to start
 [Sat Jul  4 14:55:38 1998] [debug] mod_so.c(258): loaded module setenvif_module
 [Sat Jul  4 14:55:38 1998] [debug] mod_so.c(258): loaded module unique_id_module
 /usr/local/apache/bin/apachectl restart: httpd started

 That's the best I could do.  Hope it helped.

 Worshipfully yours,

 The Web Monitor

<< Previous Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Mon Aug 17 10:43:51 EDT 1998