1 package Test::MooseX::Daemonize;
10 our $AUTHORITY = 'cpan:PERIGRIN';
16 Sub::Exporter::setup_exporter({
18 groups => { default => \@exports }
21 our $Test = Test::Builder->new;
24 my ( $daemon, $msg ) = @_;
25 unless ( my $pid = Proc::Daemon::Fork ) {
30 sleep(5); # Punt on sleep time, 5 seconds should be enough
31 $Test->ok( kill 0 => $pid or $!{EPERM}, $msg );
42 Test::MooseX::Daemonize - provides a Role that daemonizes your Moose based application.
47 This document describes MooseX::Daemonize version 0.0.1
55 ## Try to make sure we are in the test directory
56 chdir 't' if ( Cwd::cwd() !~ m|/t$| );
59 my $file = join( '/', $cwd, 'im_alive' );
60 my $daemon = FileMaker->new( pidbase => '.', filename => $file );
62 daemonize_ok( $daemon, 'child forked okay' );
63 ok( -e $file, "$file exists" );
68 Often you want to write a persistant daemon that has a pid file, and responds appropriately to Signals.
69 This module helps provide the basic infrastructure to do that.
77 The name of our daemon, defaults to $0
81 The base for our bid, defaults to /var/run/$progname
85 The file we store our PID in, defaults to /var/run/$progname/
89 If true, the process won't background. Useful for debugging. This option can be set via Getopt's -f.
99 Check to see if an instance is already running.
103 Setup a pidfile, fork, then setup the signal handlers.
107 Stop the process matching the pidfile, and unlinks the pidfile.
118 Calls C<Proc::Daemon::Init> to daemonize this process.
122 Kills the process for $pid. This will try SIGINT, and SIGTERM before falling back to SIGKILL and finally giving up.
124 =item setup_signals()
126 Setup the signal handlers, by default it only sets up handlers for SIGINT and SIGHUP
128 =item handle_sigint()
130 Handle a INT signal, by default calls C<$self->stop()>;
132 =item handle_sighup()
134 Handle a HUP signal. Nothing is done by default.
138 the C<meta()> method from L<Class::MOP::Class>
144 =for author to fill in:
145 A list of all the other modules that this module relies upon,
146 including any restrictions on versions, and an indication whether
147 the module is part of the standard Perl distribution, part of the
148 module's distribution, or must be installed separately. ]
150 Obviously L<Moose>, also L<Carp>, L<Proc::Daemon>, L<File::Flock>, L<File::Slurp>
152 =head1 INCOMPATIBILITIES
154 =for author to fill in:
155 A list of any modules that this module cannot be used in conjunction
156 with. This may be due to name conflicts in the interface, or
157 competition for system or program resources, or due to internal
158 limitations of Perl (for example, many modules that use source code
159 filters are mutually incompatible).
164 =head1 BUGS AND LIMITATIONS
166 =for author to fill in:
167 A list of known problems with the module, together with some
168 indication Whether they are likely to be fixed in an upcoming
169 release. Also a list of restrictions on the features the module
170 does provide: data types that cannot be handled, performance issues
171 and the circumstances in which they may arise, practical
172 limitations on the size of data sets, special cases that are not
175 No bugs have been reported.
177 Please report any bugs or feature requests to
178 C<bug-acme-dahut-call@rt.cpan.org>, or through the web interface at
179 L<http://rt.cpan.org>.
183 L<Proc::Daemon>, L<Daemon::Generic>, L<MooseX::Getopt>
187 Chris Prather C<< <perigrin@cpan.org> >>
190 =head1 LICENCE AND COPYRIGHT
192 Copyright (c) 2007, Chris Prather C<< <perigrin@cpan.org> >>. All rights reserved.
194 This module is free software; you can redistribute it and/or
195 modify it under the same terms as Perl itself. See L<perlartistic>.
198 =head1 DISCLAIMER OF WARRANTY
200 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
201 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
202 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
203 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
204 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
205 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
206 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
207 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
208 NECESSARY SERVICING, REPAIR, OR CORRECTION.
210 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
211 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
212 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
213 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
214 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
215 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
216 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
217 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
218 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF