Revision history for MooseX-Daemonize
+
+0.10 Sat. April 17, 2010
+ - updated copyrights
+ - removed the POE test because it was causing
+ random failures when installing from CPAN
+ and not adding enough value to keep around
+ - applied POD corrections from RT #50091
+ (thanks to Kostyuk Oleg)
+
0.09 2009-10-05
* s/no_plan => 1/'no_plan'/g (Dave Rolsky)
* Synchronize Version numbers
0.07 Saturday, May 24, 2008
* MooseX::Daemonize
- - Made default pidbase '/var/run' rather
+ - Made default pidbase '/var/run' rather
than './var/run'
-
+
* t/
- - Small fixups to pidfile testing in
+ - Small fixups to pidfile testing in
t/31.with_pid_file_and_poe.t
~ Removed the Build.PL since Module::Install
0.06 Fri. Dec. 21, 2007
* MooseX::Daemonize
- - Fix logic that kills process so it doens't always warn
+ - Fix logic that kills process so it doens't always warn
about undead process
- Added stop_timeout to allow user to control timings.
- Refactored to roles
- removed Proc::Daemon dependency
- removed File::Pid dependency
- - added exit_code and status_message to capture the
+ - added exit_code and status_message to capture the
exit code and a status message :)
- refactored start/stop/restart to use these
- added tests for this
- added a &status command which returns a bool telling
you if the daemon is running or not
- added tests for this
-
+
* Test::MooseX::Daemonize
- - updated docs
+ - updated docs
- removed Proc::Daemon dependency
* MooseX::Daemonize::Core
* MooseX::Daemonize::Pid
- added this package to replace the File::Pid stuff
-
+
* MooseX::Daemonize::Pid::File
- added this package to replace the File::Pid stuff, it is a subclass
of MooseX::Daemonize::Pid (stevan)
- added tests for this (stevan)
0.05 2007-11-18
- - Fix logic that kills process so it doens't always warn
+ - Fix logic that kills process so it doens't always warn
about undead process
- Added stop_timeout to allow user to control timings.
0.04 2007-11-11
- - Fix stupid perlcritic.t cause the Module::Starter::PBP tests were
+ - Fix stupid perlcritic.t cause the Module::Starter::PBP tests were
stupid but I didn't realize it.
0.03 2007-10-22
- Add File::Slurp to dependencies so our tests pass better
0.02 Sept 19, 2007
- - Fixed bug where sometimes the pidfile is writeable but pidbase is not -- reported by dec
- - Fixed bug where the pidfile wasn't being updated properly -- reported by dec
+ - Fixed bug where sometimes the pidfile is writeable but pidbase is not -- reported by dec
+ - Fixed bug where the pidfile wasn't being updated properly -- reported by dec
- Added is_daemon attribute
- Added another fork to make sure we short circuit out of the daemonize process properly
- Switch to File::Pid
all_from 'lib/MooseX/Daemonize.pm';
# Specific dependencies
-build_requires 'Test::More' => 0;
+build_requires 'Test::More' => 0;
+build_requires 'Test::Moose' => 0;
requires 'Moose' => 0.33;
requires 'MooseX::Getopt' => 0.07;
-MooseX-Daemonize version 0.08
+MooseX-Daemonize version 0.10
INSTALLATION
COPYRIGHT AND LICENCE
-Copyright (C) 2007-2008, Chris Prather
+Copyright (C) 2007-2010, Chris Prather
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
use Moose::Role;
use MooseX::Types::Path::Class;
-our $VERSION = "0.09";
+our $VERSION = "0.10";
with 'MooseX::Daemonize::WithPidFile',
'MooseX::Getopt';
-
+
sub OK () { 0 }
sub ERROR () { 1 }
if ($self->pidfile->is_running) {
$self->exit_code($self->OK);
- $self->status_message('Daemon is already running with pid (' . $self->pidfile->pid . ')');
+ $self->status_message('Daemon is already running with pid (' . $self->pidfile->pid . ')');
return !($self->exit_code);
}
-
- if ($self->foreground) {
+
+ if ($self->foreground) {
$self->is_daemon(1);
}
- else {
- eval { $self->daemonize };
+ else {
+ eval { $self->daemonize };
if ($@) {
$self->exit_code($self->ERROR);
$self->status_message('Start failed : ' . $@);
}
unless ($self->is_daemon) {
- $self->exit_code($self->OK);
+ $self->exit_code($self->OK);
$self->status_message('Start succeeded');
return !($self->exit_code);
}
$self->clear_exit_code;
if ($self->pidfile->is_running) {
- $self->exit_code($self->OK);
- $self->status_message('Daemon is running with pid (' . $self->pidfile->pid . ')');
+ $self->exit_code($self->OK);
+ $self->status_message('Daemon is running with pid (' . $self->pidfile->pid . ')');
}
- else {
+ else {
$self->exit_code($self->ERROR);
$self->status_message('Daemon is not running with pid (' . $self->pidfile->pid . ')');
}
# this just returns the OK
# exit code for now, but
# we should make this overridable
- $self->exit_code($self->OK);
+ $self->exit_code($self->OK);
$self->status_message("Not running");
}
=item I<pidbase Path::Class::Dir | Str>
-The base for our bid, defaults to C</var/run/$progname>
+The base for our PID, defaults to C</var/run/>
=item I<pidfile MooseX::Daemonize::Pid::File | Str>
-The file we store our PID in, defaults to C</var/run/$progname>
+The file we store our PID in, defaults to C<$pidbase/$progname.pid>
=item I<foreground Bool>
=head1 LICENCE AND COPYRIGHT
-Copyright (c) 2007-2009, Chris Prather C<< <chris@prather.org> >>. Some rights
+Copyright (c) 2007-2010, Chris Prather C<< <chris@prather.org> >>. Some rights
reserved.
This module is free software; you can redistribute it and/or
use MooseX::Getopt; # to load the NoGetopt metaclass
use Moose::Role;
-our $VERSION = '0.09';
+our $VERSION = '0.10';
use POSIX ();
=item I<dont_close_all_files>
-Setting this option to true will cause it to skip closing all the
+Setting this option to true will cause it to skip closing all the
filehandles, this is useful if you are opening things like sockets
-and such in the pre-fork.
+and such in the pre-fork.
=back
=head1 LICENCE AND COPYRIGHT
-Copyright (c) 2007-2008, Chris Prather C<< <perigrin@cpan.org> >>. All rights
+Copyright (c) 2007-2010, Chris Prather C<< <perigrin@cpan.org> >>. All rights
reserved.
Portions heavily borrowed from L<Proc::Daemon> which is copyright Earl Hood.
use strict; # because Kwalitee is pedantic
use Moose;
use Moose::Util::TypeConstraints;
-our $VERSION = '0.09';
+our $VERSION = '0.10';
-coerce 'MooseX::Daemonize::Pid'
- => from 'Int'
+coerce 'MooseX::Daemonize::Pid'
+ => from 'Int'
=> via { MooseX::Daemonize::Pid->new( pid => $_ ) };
=head1 NAME
MooseX::Daemonize::Pid - PID management for MooseX::Daemonize
-
+
=head1 DESCRIPTION
-This is a very basic Pid management object, it doesn't do all that
+This is a very basic Pid management object, it doesn't do all that
much, and mostly just serves as a base class for L<MooseX::Daemonize::Pid::File>.
=head1 ATTRIBUTES
=back
-=head1 METHODS
+=head1 METHODS
=over 4
=item B<has_pid>
-This is a predicate method to tell you if your I<pid> attribute has
+This is a predicate method to tell you if your I<pid> attribute has
been initialized yet.
=item B<is_running>
=head1 LICENCE AND COPYRIGHT
-Copyright (c) 2007-2008, Chris Prather C<< <perigrin@cpan.org> >>. All rights
+Copyright (c) 2007-2010, Chris Prather C<< <perigrin@cpan.org> >>. All rights
reserved.
This module is free software; you can redistribute it and/or
use Moose;
use Moose::Util::TypeConstraints;
-our $VERSION = '0.09';
+our $VERSION = '0.10';
use MooseX::Types::Path::Class;
use MooseX::Getopt::OptionTypeMap;
# set up some basic coercions
# that will come in handy
# - SL
-coerce 'MooseX::Daemonize::Pid::File'
- => from 'Str'
+coerce 'MooseX::Daemonize::Pid::File'
+ => from 'Str'
=> via { MooseX::Daemonize::Pid::File->new( file => $_ ) }
- => from 'ArrayRef'
- => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }
- => from 'Path::Class::File'
+ => from 'ArrayRef'
+ => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }
+ => from 'Path::Class::File'
=> via { MooseX::Daemonize::Pid::File->new( file => $_ ) };
-
+
# NOTE:
-# make sure this class plays
+# make sure this class plays
# well with MooseX::Getopt
# - SL
MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
extends 'MooseX::Daemonize::Pid';
has '+pid' => (
- default => sub {
+ default => sub {
my $self = shift;
$self->does_file_exist
? $self->file->slurp(chomp => 1)
=head1 NAME
MooseX::Daemonize::Pid::File - PID file management for MooseX::Daemonize
-
+
=head1 DESCRIPTION
This object extends L<MooseX::Daemonize::Pid> to add persistence in a Pidfile.
-This class sets up some basic coercion routines for itself so that it can
+This class sets up some basic coercion routines for itself so that it can
be created from a I<Str> (a file name), I<ArrayRef> (an array of path components
-for a filename) or a I<Path::Class::File> object.
+for a filename) or a I<Path::Class::File> object.
This class registers it's type with L<MooseX::Getopt> as well, and is expected
-to be passed on the command line as a string (which will then go through the
+to be passed on the command line as a string (which will then go through the
coercion routines mentioned above).
=head1 ATTRIBUTES
=item I<pid Int>
-This is inherited from L<MooseX:Daemonize::Pid> and extended here to
+This is inherited from L<MooseX:Daemonize::Pid> and extended here to
get it's default value from the Pidfile (if available).
=item I<file Path::Class::File | Str>
=back
-=head1 METHODS
+=head1 METHODS
=over
=item B<has_pid>
-Both of these methods are inherited from L<MooseX:Daemonize::Pid> see that
+Both of these methods are inherited from L<MooseX:Daemonize::Pid> see that
module for more information.
=item B<remove>
=head1 LICENCE AND COPYRIGHT
-Copyright (c) 2007-2008, Chris Prather C<< <perigrin@cpan.org> >>. All rights
+Copyright (c) 2007-2010, Chris Prather C<< <perigrin@cpan.org> >>. All rights
reserved.
This module is free software; you can redistribute it and/or
use strict; # cause Perl::Critic errors are annoying
use MooseX::Getopt; # to load the Getopt metaclass
use Moose::Role;
-our $VERSION = '0.09';
+our $VERSION = '0.10';
use MooseX::Daemonize::Pid::File;
has pidfile => (
# NOTE:
- # this should always be accessible
+ # this should always be accessible
# from the command line IMO
# - SL
metaclass => 'Getopt',
after 'daemonize' => sub {
my $self = shift;
# NOTE:
- # make sure that we do not have
+ # make sure that we do not have
# any bad PID values stashed around
# - SL
$self->pidfile->clear_pid;
=head1 DESCRIPTION
-This is a slightly extended basic daemonization Role, it provides
-Pidfile management along with the core daemonization features
+This is a slightly extended basic daemonization Role, it provides
+Pidfile management along with the core daemonization features
found in L<MooseX::Daemonize::Core>.
=head1 ATTRIBUTES
=item I<pidfile (is => rw, isa => MooseX::Daemonize::Pid::File)>
This attribute holds the L<MooseX::Daemonize::Pid::File> object used
-to manage the Pidfile. It will initialize the object using the
+to manage the Pidfile. It will initialize the object using the
C<init_pidfile> method (which is required by this role).
=back
=item B<has_pidfile>
-This is a predicate method to tell you if your I<pidfile> attribute has
+This is a predicate method to tell you if your I<pidfile> attribute has
been initialized yet.
=back
=item B<daemonize>
-This adds an C<after> method modifier to the C<daemonize> method (from
+This adds an C<after> method modifier to the C<daemonize> method (from
L<MooseX::Daemonize::Core>) and handles writing your Pidfile for you.
=item B<meta>
=head1 LICENCE AND COPYRIGHT
-Copyright (c) 2007-2008, Chris Prather C<< <perigrin@cpan.org> >>. All rights
+Copyright (c) 2007-2010, Chris Prather C<< <perigrin@cpan.org> >>. All rights
reserved.
Portions heavily borrowed from L<Proc::Daemon> which is copyright Earl Hood.
package Test::MooseX::Daemonize;
use strict;
-our $VERSION = '0.09';
+our $VERSION = '0.10';
our $AUTHORITY = 'cpan:PERIGRIN';
# BEGIN CARGO CULTING
This document describes MooseX::Daemonize version 0.0.1
=head1 SYNOPSIS
-
+
use File::Spec::Functions;
use File::Temp qw(tempdir);
=head1 DESCRIPTION
-This module provides some basic Test::Builder compatible test methods to
-use when writing tests for you MooseX::Daemonize based modules.
+This module provides some basic Test::Builder compatible test methods to
+use when writing tests for you MooseX::Daemonize based modules.
=head1 EXPORTED FUNCTIONS
=item B<daemonize_ok ( $daemon, ?$msg )>
-This will attempt to daemonize your C<$daemon> returning ok on
+This will attempt to daemonize your C<$daemon> returning ok on
success and not ok on failure.
=item B<check_test_output ( $daemon )>
-This is expected to be used with a C<$daemon> which does the
+This is expected to be used with a C<$daemon> which does the
B<Test::MooseX::Daemonize::Testable> role (included in this package
-see the source for more info). It will collect the test output
-from your daemon and apply it in the parent process by mucking
-around with L<Test::Builder> stuff, again, read the source for
+see the source for more info). It will collect the test output
+from your daemon and apply it in the parent process by mucking
+around with L<Test::Builder> stuff, again, read the source for
more info. If we get time we will document this more thoroughly.
=back
=head1 LICENCE AND COPYRIGHT
-Copyright (c) 2007-2008, Chris Prather C<< <perigrin@cpan.org> >>. All rights reserved.
+Copyright (c) 2007-2010, Chris Prather C<< <perigrin@cpan.org> >>. All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
+++ /dev/null
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-use File::Spec::Functions;
-
-use Test::More;
-use Test::Exception;
-use Test::Moose;
-
-use File::Temp qw(tempdir);
-
-my $dir = tempdir( CLEANUP => 1 );
-
-BEGIN {
- eval 'use POE::Kernel;';
- plan skip_all => "POE required for this test" if $@;
- plan 'no_plan';
- use_ok('MooseX::Daemonize::Core');
-
-}
-
-use constant DEBUG => 0;
-
-my $PIDFILE = catfile($dir, 'test-app.pid');
-$ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt');
-$ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt');
-
-unlink $PIDFILE; # clean up anythinf leftover by last run
-
-{
- package MyFooDaemon;
- use Moose;
- use POE;
-
- with 'MooseX::Daemonize::WithPidFile';
-
- sub init_pidfile {
- MooseX::Daemonize::Pid::File->new( file => $PIDFILE )
- }
-
- sub start {
- my $self = shift;
-
- # this tests our bad PID
- # cleanup functionality.
- print "Our parent PID is " . $self->pidfile->pid . "\n" if ::DEBUG;
-
- $self->daemonize;
- return unless $self->is_daemon;
-
- my $session = POE::Session->create(
- inline_states => {
- say_hello => sub {
- my ($kernel, $heap) = @_[KERNEL, HEAP];
-
- print "Hello from $$\n";
-
- $heap->[0] = $kernel->delay_set('say_hello', 10);
- },
- _start => sub {
- my ($kernel, $heap) = @_[KERNEL, HEAP];
- $kernel->sig( INT => 'terminate');
-
- $kernel->yield('say_hello');
- },
- terminate => sub {
- my ($kernel, $heap) = @_[KERNEL, HEAP];
- $self->pidfile->remove if $self->pidfile->pid == $$;
- }
- },
- heap => [ 0 ]
- );
-
-
- # make it easy to find with ps
- $0 = 'test-app-2';
- POE::Kernel->run;
- exit;
- }
-}
-
-my $d = MyFooDaemon->new( pidfile => $PIDFILE );
-isa_ok($d, 'MyFooDaemon');
-does_ok($d, 'MooseX::Daemonize::Core');
-does_ok($d, 'MooseX::Daemonize::WithPidFile');
-
-ok($d->has_pidfile, '... we have a pidfile value');
-
-{
- my $p = $d->pidfile;
- isa_ok($p, 'MooseX::Daemonize::Pid::File');
- #diag $p->dump;
-}
-
-ok(!(-e $PIDFILE), '... the PID file does not exist yet');
-
-lives_ok {
- $d->start;
-} '... successfully daemonized from (' . $$ . ')';
-
-my $p = $d->pidfile;
-isa_ok($p, 'MooseX::Daemonize::Pid::File');
-#diag $p->dump;
-
-sleep(2);
-
-ok($p->does_file_exist, '... the PID file exists');
-ok($p->is_running, '... the daemon process is running (' . $p->pid . ')');
-
-my $pid = $p->pid;
-if (DEBUG) {
- diag `ps $pid`;
- diag "-------";
- diag `ps -x | grep test-app`;
- diag "-------";
- diag "killing $pid";
-}
-kill INT => $p->pid;
-diag "killed $pid" if DEBUG;
-sleep(2);
-if (DEBUG) {
- diag `ps $pid`;
- diag "-------";
- diag `ps -x | grep test-app`;
-}
-
-ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')');
-ok(!(-e $PIDFILE), '... the PID file has been removed');
-
-unlink $ENV{MX_DAEMON_STDOUT};
-unlink $ENV{MX_DAEMON_STDERR};