Catalyst::Restarter::Forking: clear watcher in child process
[catagits/Catalyst-Devel.git] / lib / Catalyst / Restarter / Forking.pm
CommitLineData
2e9609df 1package Catalyst::Restarter::Forking;
2
3use Moose;
4
2e9609df 5extends 'Catalyst::Restarter';
6
7has _child => (
8 is => 'rw',
9 isa => 'Int',
10);
11
12
13sub _fork_and_start {
14 my $self = shift;
15
16 if ( my $pid = fork ) {
17 $self->_child($pid);
18 }
19 else {
835133d2 20 # Only the parent process needs to watch for changes, so the child
21 # should release any resources held by the watcher:
22 $self->_clear_watcher;
2e9609df 23 $self->start_sub->();
24 }
25}
26
27sub _kill_child {
28 my $self = shift;
29
30 return unless $self->_child;
31
32 return unless kill 0, $self->_child;
33
2e9609df 34 die "Cannot send INT signal to ", $self->_child, ": $!"
35 unless kill 'INT', $self->_child;
7d454e21 36 # If we don't wait for the child to exit, we could attempt to
37 # start a new server before the old one has given up the port it
38 # was listening on.
39 wait;
2e9609df 40}
41
c5ac9157 42__PACKAGE__->meta->make_immutable;
43
2e9609df 441;
36ff1319 45
46__END__
47
48=head1 NAME
49
50Catalyst::Restarter::Forking - Forks and restarts the child process
51
52=head1 DESCRIPTION
53
54This class forks and runs the server in a child process. When it needs
55to restart, it kills the child and creates a new one.
56
57=head1 SEE ALSO
58
59L<Catalyst::Restarter>, L<Catalyst>, <File::ChangeNotify>
60
61=head1 AUTHORS
62
63Catalyst Contributors, see Catalyst.pm
64
65=head1 COPYRIGHT
66
67This program is free software, you can redistribute it and/or modify
68it under the same terms as Perl itself.
69
70=cut