1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::Reporter::Shutdown;
21
@ISA = qw(GenTest::Reporter);
26
use GenTest::Constants;
27
use GenTest::Reporter;
35
my $primary_port = $reporter->serverVariable('port');
37
foreach my $port ($primary_port + 4, $primary_port + 2, $primary_port) {
38
my $dsn = "dbi:mysql:host=127.0.0.1:port=".$port.":user=root";
39
my $dbh = DBI->connect($dsn, undef, undef, { PrintError => 0 } );
42
if ($port == $primary_port) {
43
$pid = $reporter->serverInfo('pid');
44
} elsif (defined $dbh) {
45
my ($pid_file) = $dbh->selectrow_array('SELECT @@pid_file');
46
open (PF, $pid_file) or say("Unable to obtain pid: $!");
47
read (PF, $pid, -s $pid_file);
49
$pid =~ s{[\r\n]}{}sio;
53
say("Shutting down server on port $port via DBI...");
54
$dbh->func('shutdown', 'admin');
58
say("Shutting down server with pid $pid with SIGTERM...");
62
say("Waiting for mysqld with pid $pid to terminate...");
63
foreach my $i (1..60) {
64
if (! -e "/proc/$pid") {
71
say("... waiting complete. Just in case, killing server with pid $pid with SIGKILL ...");
80
return REPORTER_TYPE_ALWAYS;