Commit | Line | Data |
2e9609df |
1 | package Catalyst::Restarter::Forking; |
2 | |
3 | use Moose; |
4 | |
2e9609df |
5 | extends 'Catalyst::Restarter'; |
6 | |
7 | has _child => ( |
8 | is => 'rw', |
9 | isa => 'Int', |
10 | ); |
11 | |
12 | |
13 | sub _fork_and_start { |
14 | my $self = shift; |
15 | |
16 | if ( my $pid = fork ) { |
17 | $self->_child($pid); |
18 | } |
19 | else { |
20 | $self->start_sub->(); |
21 | } |
22 | } |
23 | |
24 | sub _kill_child { |
25 | my $self = shift; |
26 | |
27 | return unless $self->_child; |
28 | |
29 | return unless kill 0, $self->_child; |
30 | |
31 | local $SIG{CHLD} = 'IGNORE'; |
32 | die "Cannot send INT signal to ", $self->_child, ": $!" |
33 | unless kill 'INT', $self->_child; |
34 | } |
35 | |
36 | 1; |
36ff1319 |
37 | |
38 | __END__ |
39 | |
40 | =head1 NAME |
41 | |
42 | Catalyst::Restarter::Forking - Forks and restarts the child process |
43 | |
44 | =head1 DESCRIPTION |
45 | |
46 | This class forks and runs the server in a child process. When it needs |
47 | to restart, it kills the child and creates a new one. |
48 | |
49 | =head1 SEE ALSO |
50 | |
51 | L<Catalyst::Restarter>, L<Catalyst>, <File::ChangeNotify> |
52 | |
53 | =head1 AUTHORS |
54 | |
55 | Catalyst Contributors, see Catalyst.pm |
56 | |
57 | =head1 COPYRIGHT |
58 | |
59 | This program is free software, you can redistribute it and/or modify |
60 | it under the same terms as Perl itself. |
61 | |
62 | =cut |