3 # Copyright (C) 2004-2008 Internet Systems Consortium, Inc. ("ISC")
4 # Copyright (C) 2001 Internet Software Consortium.
6 # Permission to use, copy, modify, and/or distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
10 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 # PERFORMANCE OF THIS SOFTWARE.
18 # Id: start.pl,v 1.13 2008/01/02 23:47:01 tbox Exp
20 # Framework for starting test servers.
21 # Based on the type of server specified, check for port availability, remove
22 # temporary files, start the server, and verify that the server is running.
23 # If a server is specified, start it. Otherwise, start all servers for test.
30 # --noclean test [server [options]]
32 # --noclean - Do not cleanup files in server directory
33 # test - name of the test directory
34 # server - name of the server directory
35 # options - alternate options for the server
37 my $usage = "usage: $0 [--noclean] test-directory [server-directory [server-options]]";
39 GetOptions
('noclean' => \
$noclean);
41 my $server = $ARGV[1];
42 my $options = $ARGV[2];
48 print "No test directory: \"$test\"\n";
50 if ($server && !-d
"$test/$server") {
51 print "No server directory: \"$test/$server\"\n";
55 my $topdir = abs_path
("$test/..");
56 my $testdir = abs_path
("$test");
57 my $NAMED = $ENV{'NAMED'};
58 my $LWRESD = $ENV{'LWRESD'};
59 my $DIG = $ENV{'DIG'};
60 my $PERL = $ENV{'PERL'};
65 if ($server =~ /^ns/) {
66 &check_ports
($server);
68 &start_server
($server, $options);
69 if ($server =~ /^ns/) {
70 &verify_server
($server);
73 # Determine which servers need to be started for this test.
74 opendir DIR
, $testdir;
75 my @files = sort readdir DIR
;
78 my @ns = grep /^ns[0-9]*$/, @files;
79 my @lwresd = grep /^lwresd[0-9]*$/, @files;
80 my @ans = grep /^ans[0-9]*$/, @files;
82 # Start the servers we found.
84 foreach (@ns, @lwresd, @ans) {
98 if ($server && $server =~ /(\d+)$/) {
104 my $return = system("$PERL $topdir/testsock.pl -p 5300 $options");
105 last if ($return == 0);
107 print "$0: could not bind to server addresses, still running?\n";
108 print "I:server sockets not available\n";
110 system("$PERL $topdir/stop.pl $testdir"); # Is this the correct behavior?
113 print "I:Couldn't bind to socket (yet)\n";
126 if ($server =~ /^ns/) {
127 $cleanup_files = "{*.jnl,*.bk,*.st,named.run}";
128 $command = "$NAMED ";
130 $command .= "$options";
132 $command .= "-m record,size,mctx ";
133 $command .= "-T clienttest ";
134 $command .= "-c named.conf -d 99 -g";
136 $command .= " >named.run 2>&1 &";
137 $pid_file = "named.pid";
138 } elsif ($server =~ /^lwresd/) {
139 $cleanup_files = "{lwresd.run}";
140 $command = "$LWRESD ";
142 $command .= "$options";
144 $command .= "-m record,size,mctx ";
145 $command .= "-T clienttest ";
146 $command .= "-C resolv.conf -d 99 -g ";
147 $command .= "-i lwresd.pid -P 9210 -p 5300";
149 $command .= " >lwresd.run 2>&1 &";
150 $pid_file = "lwresd.pid";
151 } elsif ($server =~ /^ans/) {
152 $cleanup_files = "{ans.run}";
153 $command = "$PERL ./ans.pl ";
155 $command .= "$options";
159 $command .= " >ans.run 2>&1 &";
160 $pid_file = "ans.pid";
162 print "I:Unknown server type $server\n";
164 system "$PERL $topdir/stop.pl $testdir";
168 # print "I:starting server $server\n";
170 chdir "$testdir/$server";
173 unlink glob $cleanup_files;
179 while (!-f
$pid_file) {
181 print "I:Couldn't start server $server\n";
183 system "$PERL $topdir/stop.pl $testdir";
197 my $return = system("$DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd -p 5300 version.bind. chaos txt \@10.53.0.$n > dig.out");
198 last if ($return == 0);
199 print `grep ";" dig.out`;
200 if (++$tries >= 30) {
201 print "I:no response from $server\n";
203 system("$PERL $topdir/stop.pl $testdir");