You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Roy T. Fielding" <fi...@avron.ICS.UCI.EDU> on 1995/05/11 05:26:13 UTC

admin perl scripts: restart_httpd

Here is one in a series of useful administrative perl scripts
I use to maintain our server.  Feel free to do with it what you want --
if someone wants to add it to the Apache distribution, please add the 
Apache copyright first.

.......Roy
 ----------------------cut here
#!/usr/public/bin/perl
# ==========================================================================
sub usage {
    die <<"EndUsage";
USAGE:  restart_httpd

  This program sends a SIGHUP signal to the current httpd server.
  It must be run on the www machine and by the httpd's owner. 
  The effect is to force the server to re-read its config files and
  re-open its log files.  The program tails the error_log to display
  what should be a "successful restart" message.

  Created by Roy Fielding, 10 Apr 1995

EndUsage
}
if ($#ARGV >= 0) { &usage; }
# ==========================================================================
# Get defaults

umask(022);

# Set up the filenames to be used

$ServerRoot = '/usr/etc/httpd';

$PidFile  = "$ServerRoot/logs/httpd.pid";  # Server's PID file
$ErrorLog = "$ServerRoot/logs/error_log";  # Server's Error Log

# ==========================================================================
# Restart the httpd server

if (open(PID, $PidFile))
{
    chop($_ = <PID>);
    kill 1, $_;
    close(PID);
}
else
{
    die "Could not open httpd PID file: $!\n";
}

sleep(2);
system('tail','-2', $ErrorLog);

exit(0);