Merge lp:~percona-toolkit-dev/percona-toolkit/pt-kill-does-not-report-failure-exit-code-1314500 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.11

Proposed by Frank Cizmich
Status: Work in progress
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-kill-does-not-report-failure-exit-code-1314500
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.11
Diff against target: 69 lines (+21/-2)
3 files modified
bin/pt-kill (+8/-0)
t/pt-kill/basics.t (+12/-1)
t/pt-kill/execute_command.t (+1/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-kill-does-not-report-failure-exit-code-1314500
Reviewer Review Type Date Requested Status
Daniel Nichter Needs Information
Review via email: mp+233809@code.launchpad.net

Description of the change

Now waits a couple of seconds after launching daemon so it can return an error if it fails at start.
Only modified in pt-kill since it uses a heavily modified version of Daemon.pm

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

See my comment in the bug.

review: Needs Information

Unmerged revisions

618. By Frank Cizmich

minor comment change

617. By Frank Cizmich

pt-kill now reports an exit error if daemon fails to start - 1314500

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-kill'
2--- bin/pt-kill 2014-08-05 20:37:42 +0000
3+++ bin/pt-kill 2014-09-08 20:46:34 +0000
4@@ -2263,6 +2263,7 @@
5 use constant PTDEBUG => $ENV{PTDEBUG} || 0;
6
7 use POSIX qw(setsid);
8+use POSIX ":sys_wait_h";
9
10 sub new {
11 my ( $class, %args ) = @_;
12@@ -2289,6 +2290,13 @@
13 defined (my $pid = fork()) or die "Cannot fork: $OS_ERROR";
14 if ( $pid ) {
15 PTDEBUG && _d('Parent PID', $PID, 'exiting after forking child PID',$pid);
16+ # we wait a short time to capture any early failure of child process so
17+ # we can return a proper exit code
18+ sleep 2;
19+ if (waitpid($pid, WNOHANG)>0) {
20+ exit 1;
21+ }
22+ PTDEBUG && _d('Parent PID', $PID, 'exiting after forking child PID',$pid);
23 exit;
24 }
25
26
27=== modified file 't/pt-kill/basics.t'
28--- t/pt-kill/basics.t 2012-12-01 18:17:18 +0000
29+++ t/pt-kill/basics.t 2014-09-08 20:46:34 +0000
30@@ -26,7 +26,7 @@
31 plan skip_all => 'Cannot connect to sandbox master';
32 }
33 else {
34- plan tests => 6;
35+ plan tests => 7;
36 }
37
38 my $output;
39@@ -80,6 +80,17 @@
40 '--verbose'
41 );
42
43+# ############################################################################
44+# returns error code if daemon fails to start
45+# ############################################################################
46+my $cmd2 = "$trunk/bin/pt-kill -F $cnf -h 127.1 --print --daemonize --pid /tmp/non_existing_dir/pt-kill.pid";
47+my $exit_val = system($cmd2);
48+is(
49+ $exit_val >> 8,
50+ 1,
51+ 'exits with error 1 if daemon fails to start'
52+);
53+
54 # #############################################################################
55 # Reconnect if cxn lost.
56 # #############################################################################
57
58=== modified file 't/pt-kill/execute_command.t'
59--- t/pt-kill/execute_command.t 2012-10-20 19:26:33 +0000
60+++ t/pt-kill/execute_command.t 2014-09-08 20:46:34 +0000
61@@ -97,7 +97,7 @@
62 );
63
64 diag(`touch $sentinel`);
65- sleep 1;
66+ sleep 5;
67 ok(
68 !-f $pid_file,
69 "pt-kill stopped"

Subscribers

People subscribed via source and target branches

to all changes: