Those of you using
restart-aolserver
are still using the
one that does a "ps -ef" to figure out what process to kill? Yuck!
Here's the version I use, which is based on a version from ArsDigita.
(I ran the code through ns_quotehtml, so hopefully it will display
without lossage here on the BBoard. ('m a little worried about the
backslashes though... I think Don said that is fixed now?)
#!/usr/bin/perl
#
# $Id: restart-aolserver,v 1.2 2001/07/20 08:57:30 andy Exp $
#
## Restarts an AOLserver. Takes as its only argument the name of the server to kill.
## bquinn 6/16/2000 with help from {ryanlee, doug}@arsdigita
## This is a perl script because it needs to run setuid root,
## and perl has fewer security gotchas than most shells.
##
## Make sure that $PIDFILE points to the right location.
use strict;
undef %ENV;
$ENV{'PATH'} = '/sbin:/bin';
if (scalar(@ARGV) == 0) {
die "Don't run this without any arguments!";
}
my $server = shift;
$server =~ /^([w-]*)$/;
my $service_name = $1;
my $PIDFILE = "/web/aol3/log/nspid.$service_name";
my $pid;
$< = $>; # set realuid to effective uid (root)
# Get the PID of the process to kill.
open(IN,"$PIDFILE") || die "No such server
";
while(<IN>) {
chomp($_);
$pid=$_;
}
close(IN) || die "Problem closing PID file
";
# Remove the PID file. We have to delete the file to make sure that a subsequent call
# to this script will kill some other process. We delete the file before the process dies
# because if the service is set to respawn then we may delete the new pid file.
# This removing of the PID file is NOT necessary, and in leads to bugs
# as it will remove the PID file even if the kill of the process then
# fails. Therefore, comment it out entirely. --atp@piskorski.com,
# 2001/06/27
#my $cmd ="rm -f $PIDFILE";
#$cmd =~ /^(.*)$/;
#my $untaint_cmd = $1;
#`$untaint_cmd`;
# Issue the kill
$pid =~ /^(.*)$/;
my $untaint_pid = $1;
print "Killing $untaint_pid
";
kill 9, $untaint_pid;
# TODO: This is not so good. We should be trying a normal kill first,
# and then ONLY using kill -9 if the normal kill fails.
# --atp@piskorski.com, 2001/06/27