stop.pl revision 70e5a7403f0e0a3bd292b8287c5fed5772c15270
#
# Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
# Copyright (C) 2001 Internet Software Consortium.
#
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# $Id: stop.pl,v 1.12 2007/06/19 23:47:00 tbox Exp $
# Framework for stopping test servers
# Based on the type of server specified, signal the server to stop, wait
# briefly for it to die, and then kill it if it is still alive.
# If a server is specified, stop it. Otherwise, stop all servers for test.
use strict;
use Cwd 'abs_path';
# Option handling
# [--use-rndc] test [server]
#
# test - name of the test directory
# server - name of the server directory
my $usage = "usage: $0 [--use-rndc] test-directory [server-directory]";
my $use_rndc;
if ($opt eq '--use-rndc') {
$use_rndc = 1;
} else {
die "$usage\n";
}
}
my $errors = 0;
die "$usage\n" unless defined($test);
die "No test directory: \"$test\"\n" unless (-d $test);
# Global variables
my @servers;
# Determine which servers need to be stopped.
if (defined $server) {
} else {
local *DIR;
closedir DIR;
}
# Stop the server(s), pass 1: rndc.
if ($use_rndc) {
}
}
# Pass 2: SIGTERM
}
# Pass 3: SIGABRT
}
# Subroutines
# Return the full path to a given server's PID file.
sub server_pid_file {
my($server) = @_;
my $pid_file;
$pid_file = "named.pid";
$pid_file = "lwresd.pid";
$pid_file = "ans.pid";
} else {
print "I:Unknown server type $server\n";
exit 1;
}
$pid_file = "$testdir/$server/$pid_file";
}
# Read a PID.
sub read_pid {
my($pid_file) = @_;
local *FH;
if (!$result) {
print "I:$pid_file: $!\n";
unlink $pid_file;
return;
}
chomp($pid);
return $pid;
}
# Stop a named process with rndc.
sub stop_rndc {
my($server) = @_;
my $ip = "10.53.0.$1";
# Ugly, but should work.
return;
}
# Stop a server by sending a signal to it.
sub stop_signal {
return unless -f $pid_file;
return unless defined($pid);
if ($sig eq 'ABRT') {
print "I:$server didn't die when sent a SIGTERM\n";
$errors++;
}
if (!$result) {
print "I:$server died before a SIG$sig was sent\n";
unlink $pid_file;
$errors++;
}
return;
}
sub wait_for_servers {
my @pid_files = grep { defined($_) }
map { server_pid_file($_) } @servers;
$timeout--;
}
return;
}