Commit | Line | Data |
18cc5c89 |
1 | package MooseX::Daemonize::Core; |
2 | use strict; # because Kwalitee is pedantic |
3 | use Moose::Role; |
4 | |
5 | our $VERSION = 0.01; |
6 | |
7 | use Proc::Daemon; |
8 | |
9 | has is_daemon => ( |
10 | isa => 'Bool', |
11 | is => 'rw', |
12 | default => sub { 0 }, |
13 | ); |
14 | |
15 | sub daemon_fork { Proc::Daemon::Fork } |
16 | sub daemon_detach { Proc::Daemon::Init } |
17 | |
18 | sub daemonize { |
19 | my ($self) = @_; |
20 | return if $self->daemon_fork; |
21 | $self->daemon_detach; |
22 | $self->is_daemon(1); |
23 | } |
24 | |
25 | 1; |
26 | __END__ |
27 | |
28 | =head1 NAME |
29 | |
30 | MooseX::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 | |
44 | If true, the process is the backgrounded process. This is useful for example |
45 | in 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 | |
59 | Calls C<Proc::Daemon::Init> to daemonize this process. |
60 | |
61 | =item setup_signals() |
62 | |
63 | Setup the signal handlers, by default it only sets up handlers for SIGINT and SIGHUP |
64 | |
65 | =item handle_sigint() |
66 | |
67 | Handle a INT signal, by default calls C<$self->stop()> |
68 | |
69 | =item handle_sighup() |
70 | |
71 | Handle a HUP signal. By default calls C<$self->restart()> |
72 | |
73 | =item meta() |
74 | |
75 | The 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 | |
87 | Obviously 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 | |
98 | None 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 | |
112 | No bugs have been reported. |
113 | |
114 | Please report any bugs or feature requests to |
115 | C<bug-acme-dahut-call@rt.cpan.org>, or through the web interface at |
116 | L<http://rt.cpan.org>. |
117 | |
118 | =head1 SEE ALSO |
119 | |
120 | L<Proc::Daemon>, L<Daemon::Generic>, L<MooseX::Getopt> |
121 | |
122 | =head1 AUTHOR |
123 | |
124 | Chris Prather C<< <perigrin@cpan.org> >> |
125 | |
126 | =head1 THANKS |
127 | |
128 | Mike Boyko, Matt S. Trout, Stevan Little, Brandon Black, Ash Berlin and the |
129 | #moose denzians |
130 | |
131 | Some bug fixes sponsored by Takkle Inc. |
132 | |
133 | =head1 LICENCE AND COPYRIGHT |
134 | |
135 | Copyright (c) 2007, Chris Prather C<< <perigrin@cpan.org> >>. All rights |
136 | reserved. |
137 | |
138 | This module is free software; you can redistribute it and/or |
139 | modify it under the same terms as Perl itself. See L<perlartistic>. |
140 | |
141 | |
142 | =head1 DISCLAIMER OF WARRANTY |
143 | |
144 | BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
145 | FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
146 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
147 | PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER |
148 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
149 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE |
150 | ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH |
151 | YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL |
152 | NECESSARY SERVICING, REPAIR, OR CORRECTION. |
153 | |
154 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
155 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
156 | REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE |
157 | LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, |
158 | OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE |
159 | THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
160 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
161 | FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
162 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
163 | SUCH DAMAGES. |