removing handles for pidfile, we need to make this into a role
[gitmo/MooseX-Daemonize.git] / lib / MooseX / Daemonize / Core.pm
CommitLineData
18cc5c89 1package MooseX::Daemonize::Core;
2use strict; # because Kwalitee is pedantic
3use Moose::Role;
4
5our $VERSION = 0.01;
6
7use Proc::Daemon;
8
9has is_daemon => (
10 isa => 'Bool',
11 is => 'rw',
12 default => sub { 0 },
13);
14
15sub daemon_fork { Proc::Daemon::Fork }
16sub daemon_detach { Proc::Daemon::Init }
17
18sub daemonize {
19 my ($self) = @_;
20 return if $self->daemon_fork;
21 $self->daemon_detach;
22 $self->is_daemon(1);
23}
24
251;
26__END__
27
28=head1 NAME
29
30MooseX::Daemonize::Core - provides a Role the core daemonization features
31
32=head1 VERSION
33
34=head1 SYNOPSIS
35
36=head1 DESCRIPTION
37
38=head1 ATTRIBUTES
39
40=over
41
42=item is_daemon Bool
43
44If true, the process is the backgrounded process. This is useful for example
45in an after 'start' => sub { } block
46
47=back
48
49=head1 METHODS
50
51=over
52
53=item daemon_fork()
54
55=item daemon_detach()
56
57=item daemonize()
58
59Calls C<Proc::Daemon::Init> to daemonize this process.
60
61=item setup_signals()
62
63Setup the signal handlers, by default it only sets up handlers for SIGINT and SIGHUP
64
65=item handle_sigint()
66
67Handle a INT signal, by default calls C<$self->stop()>
68
69=item handle_sighup()
70
71Handle a HUP signal. By default calls C<$self->restart()>
72
73=item meta()
74
75The C<meta()> method from L<Class::MOP::Class>
76
77=back
78
79=head1 DEPENDENCIES
80
81=for author to fill in:
82 A list of all the other modules that this module relies upon,
83 including any restrictions on versions, and an indication whether
84 the module is part of the standard Perl distribution, part of the
85 module's distribution, or must be installed separately. ]
86
87Obviously L<Moose>, and L<Proc::Daemon>
88
89=head1 INCOMPATIBILITIES
90
91=for author to fill in:
92 A list of any modules that this module cannot be used in conjunction
93 with. This may be due to name conflicts in the interface, or
94 competition for system or program resources, or due to internal
95 limitations of Perl (for example, many modules that use source code
96 filters are mutually incompatible).
97
98None reported.
99
100
101=head1 BUGS AND LIMITATIONS
102
103=for author to fill in:
104 A list of known problems with the module, together with some
105 indication Whether they are likely to be fixed in an upcoming
106 release. Also a list of restrictions on the features the module
107 does provide: data types that cannot be handled, performance issues
108 and the circumstances in which they may arise, practical
109 limitations on the size of data sets, special cases that are not
110 (yet) handled, etc.
111
112No bugs have been reported.
113
114Please report any bugs or feature requests to
115C<bug-acme-dahut-call@rt.cpan.org>, or through the web interface at
116L<http://rt.cpan.org>.
117
118=head1 SEE ALSO
119
120L<Proc::Daemon>, L<Daemon::Generic>, L<MooseX::Getopt>
121
122=head1 AUTHOR
123
124Chris Prather C<< <perigrin@cpan.org> >>
125
126=head1 THANKS
127
128Mike Boyko, Matt S. Trout, Stevan Little, Brandon Black, Ash Berlin and the
129#moose denzians
130
131Some bug fixes sponsored by Takkle Inc.
132
133=head1 LICENCE AND COPYRIGHT
134
135Copyright (c) 2007, Chris Prather C<< <perigrin@cpan.org> >>. All rights
136reserved.
137
138This module is free software; you can redistribute it and/or
139modify it under the same terms as Perl itself. See L<perlartistic>.
140
141
142=head1 DISCLAIMER OF WARRANTY
143
144BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
145FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
146OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
147PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
148EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
149WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
150ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
151YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
152NECESSARY SERVICING, REPAIR, OR CORRECTION.
153
154IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
155WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
156REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
157LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
158OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
159THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
160RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
161FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
162SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
163SUCH DAMAGES.