Index: openacs-4/bin/restart-aolserver
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/bin/Attic/restart-aolserver,v
diff -u -r1.1 -r1.2
--- openacs-4/bin/restart-aolserver	13 Mar 2001 22:59:26 -0000	1.1
+++ openacs-4/bin/restart-aolserver	20 Jan 2003 14:25:44 -0000	1.2
@@ -1,55 +1,51 @@
-#!/usr/local/bin/perl
-# $Id$
-
-## Restarts an AOLserver. Takes as its only argument the name of the
-## server to kill.
-
+#!/usr/bin/perl
+## 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;
 
+use strict;
+undef %ENV;
 $ENV{'PATH'} = '/sbin:/bin';
-my @superusers=('james','jsc','brucek','dbryant');
 
-my $name;
-($name) = (getpwuid($<))[0];
-
-my $superuser = 0;
-if (grep ($name eq $_,@superusers) ) {
-   $superuser = 1;
+if (scalar(@ARGV) == 0) {
+     die "Don't run this without any arguments!";
 }
 
-if (scalar(@ARGV) == 0 && !$superuser) {
-    die "Don't run this without any arguments!\n";
-}
-
 my $server = shift;
-# untaint this variable to make suidperl happy
 $server =~ /^([\w-]*)$/;
-my $servername = $1;
+my $service_name = $1;
+my $PIDFILE = "/usr/local/aolserver/log/nspid.$service_name";
+my $pid;
 
-if ($server && !$servername) {
-   die "An AOL servername should only have letters, numbers, underscores, or a dash.\nYou told us to restart $server, and we can't do that.
+$< = $>; # set realuid to effective uid (root)
 
-You just want to say something like \"restart-aolserver student000\".
-"
-} elsif (!$servername && !$superuser) {
-   die "We need something besides the empty string to restart.\n"
+# Get the PID of the process to kill.
+
+open(IN,"$PIDFILE") || die "No such server\n";
+while(<IN>) {
+    chomp($_);
+    $pid=$_;
 }
+close(IN) || die "Problem closing PID file\n";
 
-$< = $>; # set realuid to effective uid (root)
+# 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.
 
-## get the PIDs of all jobdirect servers
-open(PID, "/usr/bin/ps -ef |") || die $!;
-my @pids;
-while (<PID>) {
-  next unless /^\s*\S+\s+(\d+).*nsd.*\/$servername\./;
-  my $pid = $1;
-  push(@pids, $pid);
-}
-close PID;
+my $cmd ="rm -f $PIDFILE";
+$cmd =~ /^(.*)$/;
+my $untaint_cmd = $1;
+`$untaint_cmd`;
 
-print "Killing ", join(" ", @pids), "\n";
-kill 'KILL', @pids;
+# Issue the kill
+$pid =~ /^(.*)$/;
+my $untaint_pid = $1;
+print "Killing $untaint_pid\n";
+kill 9, $untaint_pid;
 
+