0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2010, 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# $Id: stop.pl,v 1.2 2010/06/17 05:38:05 marka Exp $
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Framework for stopping test servers
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Based on the type of server specified, signal the server to stop, wait
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# briefly for it to die, and then kill it if it is still alive.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# If a server is specified, stop it. Otherwise, stop all servers for test.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Option handling
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# [--use-rndc] test [server]
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# test - name of the test directory
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# server - name of the server directory
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrewsmy $usage = "usage: $0 [--use-rndc] test-directory [server-directory]";
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews die "$usage\n";
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrewsdie "No test directory: \"$test\"\n" unless (-d $test);
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrewsdie "No server directory: \"$server\"\n" if (defined($server) && !-d "$test/$server");
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Global variables
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Determine which servers need to be stopped.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrewsif (defined $server) {
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Stop the server(s), pass 1: rndc.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Pass 2: SIGTERM
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Pass 3: SIGABRT
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Subroutines
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Return the full path to a given server's PID file.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews print "I:Unknown server type $server\n";
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Read a PID.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews print "I:$pid_file: $!\n";
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Stop a named process with rndc.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews # Ugly, but should work.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews system("$ENV{RNDC} -c $testdir/../common/rndc.conf -s $ip -p 9953 stop | sed 's/^/I:$server /'");
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews# Stop a server by sending a signal to it.
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews return unless -f $pid_file;
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews return unless defined($pid);
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews print "I:$server didn't die when sent a SIGTERM\n";
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews print "I:$server died before a SIG$sig was sent\n";
43c770b9987375e9e0efa19617b22e8e6a748a63Mark Andrews my @pid_files = grep { defined($_) }