X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FDaemonize.pm;h=4cb6cb374697df86267a3b446d3390f099b5d4bc;hb=25a727cc1b7fc1dcbf22894fefb23ea88ec2799d;hp=5c627bac6eb8670831adf583d419d09a02b964ef;hpb=05b96f4d04d93f2344602f7b3ef43da01c0a2794;p=gitmo%2FMooseX-Daemonize.git diff --git a/lib/MooseX/Daemonize.pm b/lib/MooseX/Daemonize.pm index 5c627ba..4cb6cb3 100644 --- a/lib/MooseX/Daemonize.pm +++ b/lib/MooseX/Daemonize.pm @@ -2,8 +2,9 @@ package MooseX::Daemonize; use strict; # because Kwalitee is pedantic use Moose::Role; use MooseX::Types::Path::Class; +use File::Path qw(make_path); -our $VERSION = '0.13'; +our $VERSION = '0.16'; with 'MooseX::Daemonize::WithPidFile', 'MooseX::Getopt'; @@ -21,6 +22,7 @@ has progname => ( ( my $name = lc $_[0]->meta->name ) =~ s/::/_/g; return $name; }, + documentation => 'the name of the daemon', ); has pidbase => ( @@ -31,6 +33,7 @@ has pidbase => ( required => 1, lazy => 1, default => sub { Path::Class::Dir->new('', 'var', 'run') }, + documentation => 'the base for our pid (default: /var/run)', ); has basedir => ( @@ -41,6 +44,7 @@ has basedir => ( required => 1, lazy => 1, default => sub { Path::Class::Dir->new('/') }, + documentation => 'the directory to chdir to (default: /)', ); has foreground => ( @@ -49,13 +53,15 @@ has foreground => ( isa => 'Bool', is => 'ro', default => sub { 0 }, + documentation => 'if true, the process won\'t background', ); has stop_timeout => ( metaclass => 'Getopt', isa => 'Int', is => 'rw', - default => sub { 2 } + default => sub { 2 }, + documentation => 'number of seconds to wait for the process to stop, before trying harder to kill it (default: 2 s)', ); # internal book-keeping @@ -81,6 +87,15 @@ has exit_code => ( sub init_pidfile { my $self = shift; my $file = $self->pidbase . '/' . $self->progname . '.pid'; + + if ( !-d $self->pidbase ) { + make_path( $self->pidbase, { error => \my $err } ); + if (@$err) { + confess sprintf( "Cannot create pidbase directory '%s': %s", + $self->pidbase, @$err ); + } + } + confess "Cannot write to $file" unless (-e $file ? -w $file : -w $self->pidbase); MooseX::Daemonize::Pid::File->new( file => $file ); } @@ -302,9 +317,9 @@ __END__ MooseX::Daemonize - Role for daemonizing your Moose based application -=head1 VERSION +=head1 WARNING -This document describes MooseX::Daemonize version 0.05 +The maintainers of this module now recommend using L instead. =head1 SYNOPSIS @@ -381,6 +396,10 @@ The name of our daemon, defaults to C<$package_name =~ s/::/_/>; The base for our PID, defaults to C +=item I + +The directory we chdir to; defaults to C. + =item I The file we store our PID in, defaults to C<$pidbase/$progname.pid> @@ -559,7 +578,7 @@ L. =head1 SEE ALSO -L, L +L, L, L =head1 AUTHORS