~xnox/ubuntu/saucy/drizzle/merge

« back to all changes in this revision

Viewing changes to tests/randgen/lib/GenTest/Reporter/Shutdown.pm

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.2.11) (2.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20120619104649-9ij634mxm4x8pp4l
Tags: 1:7.1.36-stable-1ubuntu1
* Merge from Debian unstable. (LP: #987575)
  Remaining changes:
  - Added upstart script.
* debian/drizzle.upstart: dropped logger since upstart logs job
  output now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
 
2
# Use is subject to license terms.
 
3
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
# USA
 
17
 
 
18
package GenTest::Reporter::Shutdown;
 
19
 
 
20
require Exporter;
 
21
@ISA = qw(GenTest::Reporter);
 
22
 
 
23
use strict;
 
24
use DBI;
 
25
use GenTest;
 
26
use GenTest::Constants;
 
27
use GenTest::Reporter;
 
28
use Data::Dumper;
 
29
use IPC::Open2;
 
30
use IPC::Open3;
 
31
 
 
32
sub report {
 
33
        my $reporter = shift;
 
34
 
 
35
        my $primary_port = $reporter->serverVariable('port');
 
36
 
 
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 } );
 
40
 
 
41
                my $pid;
 
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);
 
48
                        close (PF);
 
49
                        $pid =~ s{[\r\n]}{}sio;
 
50
                }
 
51
 
 
52
                if (defined $dbh) {
 
53
                        say("Shutting down server on port $port via DBI...");
 
54
                        $dbh->func('shutdown', 'admin');
 
55
                }
 
56
 
 
57
                if (defined $pid) {
 
58
                        say("Shutting down server with pid $pid with SIGTERM...");
 
59
                        kill(15, $pid);
 
60
 
 
61
                        if (!osWindows()) {
 
62
                                say("Waiting for mysqld with pid $pid to terminate...");
 
63
                                foreach my $i (1..60) {
 
64
                                        if (! -e "/proc/$pid") {
 
65
                                                print "\n";
 
66
                                                last;
 
67
                                        }
 
68
                                        sleep(1);
 
69
                                        print "+";
 
70
                                }
 
71
                                say("... waiting complete. Just in case, killing server with pid $pid with SIGKILL ...");
 
72
                                kill(9, $pid);
 
73
                        }
 
74
                }
 
75
        }       
 
76
        return STATUS_OK;
 
77
}
 
78
 
 
79
sub type {
 
80
        return REPORTER_TYPE_ALWAYS;
 
81
}
 
82
 
 
83
1;