r77585 - in /branches/upstream/libapp-daemon-perl/current: .cvsignore .licensizer.yml Changes Daemon.pm MANIFEST MANIFEST.SKIP META.yml Makefile.PL README adm/release t/003CmdLine.t
carnil at users.alioth.debian.org
carnil at users.alioth.debian.org
Tue Jul 19 05:40:09 UTC 2011
Author: carnil
Date: Tue Jul 19 05:40:07 2011
New Revision: 77585
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=77585
Log:
[svn-upgrade] new version libapp-daemon-perl (0.12)
Added:
branches/upstream/libapp-daemon-perl/current/.licensizer.yml
branches/upstream/libapp-daemon-perl/current/MANIFEST.SKIP
branches/upstream/libapp-daemon-perl/current/t/003CmdLine.t
Removed:
branches/upstream/libapp-daemon-perl/current/.cvsignore
Modified:
branches/upstream/libapp-daemon-perl/current/Changes
branches/upstream/libapp-daemon-perl/current/Daemon.pm
branches/upstream/libapp-daemon-perl/current/MANIFEST
branches/upstream/libapp-daemon-perl/current/META.yml
branches/upstream/libapp-daemon-perl/current/Makefile.PL
branches/upstream/libapp-daemon-perl/current/README
branches/upstream/libapp-daemon-perl/current/adm/release
Added: branches/upstream/libapp-daemon-perl/current/.licensizer.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/.licensizer.yml?rev=77585&op=file
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/.licensizer.yml (added)
+++ branches/upstream/libapp-daemon-perl/current/.licensizer.yml Tue Jul 19 05:40:07 2011
@@ -1,0 +1,18 @@
+# .licensizer.yml
+
+author:
+ text: |
+ 2011, Mike Schilli <cpan at perlmeister.com>
+ header: AUTHORS
+ mode: verbatim
+
+license:
+ text: |
+ Copyright 2011 by Mike Schilli, all rights reserved.
+ This program is free software, you can redistribute it and/or
+ modify it under the same terms as Perl itself.
+ header: LEGALESE
+
+path_exclude:
+ - t/
+ - blib/
Modified: branches/upstream/libapp-daemon-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/Changes?rev=77585&op=diff
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/Changes (original)
+++ branches/upstream/libapp-daemon-perl/current/Changes Tue Jul 19 05:40:07 2011
@@ -1,4 +1,15 @@
Revision history for Perl extension App::Daemon.
+
+0.12 (07/18/2011)
+ (ms) 'status' now doesn't write to the logfile (suggested by Brian Pitts)
+ (ms) 'stop' now verifies if the process is still up, and retries
+ $App::Daemon::kill_retries times (defaults to 3) times, with
+ 1-second sleeps in between.
+ (ms) Upon successful 'stop', pid file now gets removed (suggested by
+ Brian Pitts)
+ (ms) 'status' now triggers exit codes
+ in compliance with http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html (suggested by Brian Pitts)
+ (ms) using SIGTERM now instead of SIGINT to terminate a process
0.11 (08/28/2010)
(ms) Fixed test suite.
Modified: branches/upstream/libapp-daemon-perl/current/Daemon.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/Daemon.pm?rev=77585&op=diff
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/Daemon.pm (original)
+++ branches/upstream/libapp-daemon-perl/current/Daemon.pm Tue Jul 19 05:40:07 2011
@@ -2,11 +2,10 @@
use strict;
use warnings;
-our $VERSION = '0.11';
+our $VERSION = '0.12';
use Getopt::Std;
use Pod::Usage;
-use Log::Log4perl qw(:easy);
use File::Basename;
use Proc::ProcessTable;
use Log::Log4perl qw(:easy);
@@ -17,11 +16,21 @@
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(daemonize cmd_line_parse detach);
+use constant LSB_OK => 0;
+use constant LSB_DEAD_PID_EXISTS => 1;
+use constant LSB_DEAD_LOCK_EXISTS => 2;
+use constant LSB_NOT_RUNNING => 3;
+use constant LSB_UNKNOWN => 4;
+use constant ALREADY_RUNNING => 150;
+
our ($pidfile, $logfile, $l4p_conf, $as_user, $background,
$loglevel, $action, $appname);
$action = "";
$appname = appname();
+our $kill_retries = 3;
+our $kill_sig = SIGTERM; # maps to 15 via POSIX.pm
+
###########################################
sub cmd_line_parse {
###########################################
@@ -80,6 +89,8 @@
if( Log::Log4perl->initialized() ) {
DEBUG "Log4perl already initialized, doing nothing";
+ } elsif( $action eq "status" ) {
+ Log::Log4perl->easy_init( $loglevel );
} elsif( $l4p_conf ) {
Log::Log4perl->init( $l4p_conf );
} elsif( $logfile ) {
@@ -111,33 +122,53 @@
}
if($action eq "status") {
- status();
- exit 0;
+ exit status();
}
if($action eq "stop" or $action eq "restart") {
+ my $exit_code = LSB_NOT_RUNNING;
+
if(-f $pidfile) {
my $pid = pid_file_read();
if(kill 0, $pid) {
- kill 2, $pid;
+ kill $kill_sig, $pid;
+ my $killed = 0;
+ for (1..$kill_retries) {
+ if(!kill 0, $pid) {
+ INFO "Process $pid stopped successfully.";
+ unlink $pidfile or die "Can't remove $pidfile ($!)";
+ $exit_code = LSB_OK;
+ $killed++;
+ last;
+ }
+ INFO "Process $pid still running, waiting ...";
+ sleep 1;
+ }
+ if(! $killed) {
+ ERROR "Process $pid still up, out of retries, giving up.";
+ $exit_code = LSB_DEAD_PID_EXISTS;
+ }
} else {
ERROR "Process $pid not running\n";
unlink $pidfile or die "Can't remove $pidfile ($!)";
+ $exit_code = LSB_NOT_RUNNING;
}
} else {
ERROR "According to my pidfile, there's no instance ",
"of me running.";
- }
+ $exit_code = LSB_NOT_RUNNING;
+ }
+
if($action eq "restart") {
sleep 1;
} else {
- INFO "Process $$ stopped by request.";
- exit 0;
+ exit $exit_code;
}
}
if ( my $num = pid_file_process_running() ) {
- LOGDIE "Already running: $num (pidfile=$pidfile)\n";
+ LOGWARN "Already running: $num (pidfile=$pidfile)\n";
+ exit ALREADY_RUNNING;
}
if( $background ) {
@@ -220,20 +251,35 @@
###########################################
sub status {
###########################################
+
+ # Define exit codes according to
+ # http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
+ my $exit_code = LSB_UNKNOWN;
+
print "Pid file: $pidfile\n";
if(-f $pidfile) {
my $pid = pid_file_read();
+ my $running = process_running($pid);
print "Pid in file: $pid\n";
- print "Running: ", process_running($pid) ? "yes" : "no", "\n";
+ print "Running: ", $running ? "yes" : "no", "\n";
+ if($running) {
+ # see above
+ $exit_code = LSB_OK;
+ } else {
+ # see above
+ $exit_code = LSB_DEAD_PID_EXISTS;
+ }
} else {
print "No pidfile found\n";
+ $exit_code = LSB_NOT_RUNNING;
}
my @cmdlines = processes_running_by_name( $appname );
print "Name match: ", scalar @cmdlines, "\n";
for(@cmdlines) {
print " ", $_, "\n";
}
- return 1;
+
+ return $exit_code;
}
@@ -449,9 +495,17 @@
=item stop
-will find the daemon's PID in the pidfile and send it a kill signal. It
-won't verify if this actually shut down the daemon or if it's immune to
-the kill signal.
+will find the daemon's PID in the pidfile and send it a SIGTERM signal. It
+will verify $App::Daemon::kill_retries times if the process is still alive,
+with 1-second sleeps in between.
+
+To have App::Daemon send a different signal than SIGTERM (e.g., SIGINT), set
+
+ use POSIX;
+ $App::Daemon::kill_sig = SIGINT;
+
+Note that his requires the numerial value (SIGINT via POSIX.pm), not a
+string like "SIGINT".
=item status
@@ -482,6 +536,26 @@
Pid in file: 14914
Running: no
Name match: 0
+
+The status commands exit code complies with
+
+ http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
+
+and returns
+
+ 0: if the process is up and running
+ 1: the process is dead but the pid file still exists
+ 3: the process is not running
+
+These constants are defined within App::Daemon to help writing test
+scripts:
+
+ use constant LSB_OK => 0;
+ use constant LSB_DEAD_PID_EXISTS => 1;
+ use constant LSB_DEAD_LOCK_EXISTS => 2;
+ use constant LSB_NOT_RUNNING => 3;
+ use constant LSB_UNKNOWN => 4;
+ use constant ALREADY_RUNNING => 150;
=back
@@ -601,8 +675,8 @@
=head1 AUTHOR
-Mike Schilli, cpan at perlmeister.com
-
+ 2011, Mike Schilli <cpan at perlmeister.com>
+
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2008 by Mike Schilli
@@ -611,4 +685,11 @@
it under the same terms as Perl itself, either Perl version 5.8.5 or,
at your option, any later version of Perl 5 you may have available.
-=cut
+=cut
+
+=head1 LICENSE
+
+Copyright 2011 by Mike Schilli, all rights reserved.
+This program is free software, you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
Modified: branches/upstream/libapp-daemon-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/MANIFEST?rev=77585&op=diff
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/MANIFEST (original)
+++ branches/upstream/libapp-daemon-perl/current/MANIFEST Tue Jul 19 05:40:07 2011
@@ -1,4 +1,4 @@
-.cvsignore
+.licensizer.yml
adm/release
Changes
Daemon.pm
@@ -6,7 +6,9 @@
eg/test-detach
Makefile.PL
MANIFEST
+MANIFEST.SKIP
README
t/001Basic.t
t/002Params.t
+t/003CmdLine.t
META.yml Module meta-data (added by MakeMaker)
Added: branches/upstream/libapp-daemon-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/MANIFEST.SKIP?rev=77585&op=file
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/MANIFEST.SKIP (added)
+++ branches/upstream/libapp-daemon-perl/current/MANIFEST.SKIP Tue Jul 19 05:40:07 2011
@@ -1,0 +1,7 @@
+\.git
+\.gz$
+Makefile$
+Makefile.old
+\.bak$
+^pm_to_blib$
+^blib/
Modified: branches/upstream/libapp-daemon-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/META.yml?rev=77585&op=diff
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/META.yml (original)
+++ branches/upstream/libapp-daemon-perl/current/META.yml Tue Jul 19 05:40:07 2011
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: App-Daemon
-version: 0.11
+version: 0.12
abstract: Start an Application as a Daemon
author:
- Mike Schilli <m at perlmeister.com>
@@ -18,6 +18,7 @@
Log::Log4perl: 1.0
Pod::Usage: 0
Proc::ProcessTable: 0
+ Sysadm::Install: 0.37
Test::More: 0
resources:
repository: http://github.com/mschilli/app-daemon
@@ -25,7 +26,7 @@
directory:
- t
- inc
-generated_by: ExtUtils::MakeMaker version 6.55_02
+generated_by: ExtUtils::MakeMaker version 6.56
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
Modified: branches/upstream/libapp-daemon-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/Makefile.PL?rev=77585&op=diff
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/Makefile.PL (original)
+++ branches/upstream/libapp-daemon-perl/current/Makefile.PL Tue Jul 19 05:40:07 2011
@@ -22,6 +22,7 @@
File::Basename => 0,
Test::More => 0,
File::Temp => 0,
+ Sysadm::Install => 0.37,
}, # e.g., Module::Name => 1.1
$ExtUtils::MakeMaker::VERSION >= 6.50 ? (%$meta_merge) : (),
($] >= 5.005 ? ## Add these new keywords supported since 5.005
Modified: branches/upstream/libapp-daemon-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/README?rev=77585&op=diff
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/README (original)
+++ branches/upstream/libapp-daemon-perl/current/README Tue Jul 19 05:40:07 2011
@@ -1,5 +1,5 @@
######################################################################
- App::Daemon 0.11
+ App::Daemon 0.12
######################################################################
NAME
@@ -73,9 +73,18 @@
program is run in foreground mode for testing purposes.
stop
- will find the daemon's PID in the pidfile and send it a kill signal.
- It won't verify if this actually shut down the daemon or if it's
- immune to the kill signal.
+ will find the daemon's PID in the pidfile and send it a SIGTERM
+ signal. It will verify $App::Daemon::kill_retries times if the
+ process is still alive, with 1-second sleeps in between.
+
+ To have App::Daemon send a different signal than SIGTERM (e.g.,
+ SIGINT), set
+
+ use POSIX;
+ $App::Daemon::kill_sig = SIGINT;
+
+ Note that his requires the numerial value (SIGINT via POSIX.pm), not
+ a string like "SIGINT".
status
will print out diagnostics on what the status of the daemon is.
@@ -105,6 +114,26 @@
Pid in file: 14914
Running: no
Name match: 0
+
+ The status commands exit code complies with
+
+ http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
+
+ and returns
+
+ 0: if the process is up and running
+ 1: the process is dead but the pid file still exists
+ 3: the process is not running
+
+ These constants are defined within App::Daemon to help writing test
+ scripts:
+
+ use constant LSB_OK => 0;
+ use constant LSB_DEAD_PID_EXISTS => 1;
+ use constant LSB_DEAD_LOCK_EXISTS => 2;
+ use constant LSB_NOT_RUNNING => 3;
+ use constant LSB_UNKNOWN => 4;
+ use constant ALREADY_RUNNING => 150;
Command Line Options
-X Foreground mode. Log messages go to the screen.
@@ -204,8 +233,8 @@
shell prompt immediately.
AUTHOR
- Mike Schilli, cpan at perlmeister.com
-
+ 2011, Mike Schilli <cpan at perlmeister.com>
+
COPYRIGHT AND LICENSE
Copyright (C) 2008 by Mike Schilli
@@ -213,3 +242,8 @@
under the same terms as Perl itself, either Perl version 5.8.5 or, at
your option, any later version of Perl 5 you may have available.
+LICENSE
+ Copyright 2011 by Mike Schilli, all rights reserved. This program is
+ free software, you can redistribute it and/or modify it under the same
+ terms as Perl itself.
+
Modified: branches/upstream/libapp-daemon-perl/current/adm/release
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/adm/release?rev=77585&op=diff
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/adm/release (original)
+++ branches/upstream/libapp-daemon-perl/current/adm/release Tue Jul 19 05:40:07 2011
@@ -5,4 +5,5 @@
# Available at http://perlmeister.com/scripts
use lib "$ENV{HOME}/perl-modules";
use ModDevUtils;
+system("licensizer");
ModDevUtils::release(0) or exit 0;
Added: branches/upstream/libapp-daemon-perl/current/t/003CmdLine.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libapp-daemon-perl/current/t/003CmdLine.t?rev=77585&op=file
==============================================================================
--- branches/upstream/libapp-daemon-perl/current/t/003CmdLine.t (added)
+++ branches/upstream/libapp-daemon-perl/current/t/003CmdLine.t Tue Jul 19 05:40:07 2011
@@ -1,0 +1,42 @@
+# launch app-daemon
+use File::Temp qw(tempdir);
+use FindBin qw($Bin);
+use Sysadm::Install qw(:all);
+use Test::More;
+use App::Daemon;
+
+use Log::Log4perl qw(:easy);
+# Log::Log4perl->easy_init($DEBUG);
+
+plan tests => 6;
+
+my $tempdir = tempdir( CLEANUP => 1 );
+
+my ( $stdout, $stderr, $rc );
+my @cmdline = ( $^X, "-I$Bin/../blib/lib", "$Bin/../eg/test-daemon",
+ "-l", "$tempdir/log", "-p", "$tempdir/pid" );
+
+ # start sleep daemon
+( $stdout, $stderr, $rc ) = tap @cmdline, "start";
+is $rc, 0, "app start";
+
+ # start once again
+( $stdout, $stderr, $rc ) = tap @cmdline, "start";
+is $rc>>8, App::Daemon::ALREADY_RUNNING, "app start again";
+
+ # check status
+( $stdout, $stderr, $rc ) = tap @cmdline, "status";
+is $rc>>8, App::Daemon::LSB_OK, "status started";
+
+ # stop daemon
+( $stdout, $stderr, $rc ) = tap @cmdline, "stop";
+is $rc, 0, "app stop";
+
+ # stop daemon again
+( $stdout, $stderr, $rc ) = tap @cmdline, "stop";
+is $rc>>8, App::Daemon::LSB_NOT_RUNNING, "app stop again";
+
+ # check status
+( $stdout, $stderr, $rc ) = tap @cmdline, "status";
+is $rc>>8, App::Daemon::LSB_NOT_RUNNING, "status stopped";
+
More information about the Pkg-perl-cvs-commits
mailing list