#!/usr/bin/perl # Start, stop and restart the Web server without becoming superuser # each time. # See "Web Security, A Step-by-Step Reference Guide" by Lincoln Stein, page 189 # These constants will need to be adjusted. $PID_FILE = '/usr/local/etc/logs/httpd.pid'; $HTTPD = '/usr/local/etc/httpd -d /usr/local/etc/httpd'; # These prevent taint warnings while running suid $ENV{PATH}='/bin:/usr/bin'; $ENV{IFS}=''; # Do different things depending on our name ($name) = $0 =~ m|([^/]+)$|; if ($name eq 'start_http') { system $HTTPD and die "Unable to start HTTP"; print "HTTP started.\n"; exit 0; } # extract the pid and confirm # that it is numeric; $pid = `cat $PID_FILE`; $pid =~ /(\d+)/ or die "PID $pid not numeric"; $pid = $1; if ($name eq 'stop_http') { kill 'TERM',$pid or die "Unable to signal HTTP"; print "HTTP stopped.\n"; exit 0; } if ($name eq 'restart_http') { kill 'HUP',$pid or die "Unable to signal HTTP"; print "HTTP restarted.\n"; exit 0; } die "Script must be named start_http, stop_http, or restart_http.\n";