Catalyst::Restarter::Forking - Forks and restarts the child process


Catalyst-Devel documentation Contained in the Catalyst-Devel distribution.

Index


Code Index:

NAME

Top

Catalyst::Restarter::Forking - Forks and restarts the child process

DESCRIPTION

Top

This class forks and runs the server in a child process. When it needs to restart, it kills the child and creates a new one.

SEE ALSO

Top

Catalyst::Restarter, Catalyst, <File::ChangeNotify>

AUTHORS

Top

Catalyst Contributors, see Catalyst.pm

COPYRIGHT

Top


Catalyst-Devel documentation Contained in the Catalyst-Devel distribution.

package Catalyst::Restarter::Forking;

use Moose;

extends 'Catalyst::Restarter';

has _child => (
    is  => 'rw',
    isa => 'Int',
);


sub _fork_and_start {
    my $self = shift;

    if ( my $pid = fork ) {
        $self->_child($pid);
    }
    else {
        $self->start_sub->();
    }
}

sub _kill_child {
    my $self = shift;

    return unless $self->_child;

    return unless kill 0, $self->_child;

    die "Cannot send INT signal to ", $self->_child, ": $!"
        unless kill 'INT', $self->_child;
    # If we don't wait for the child to exit, we could attempt to
    # start a new server before the old one has given up the port it
    # was listening on.
    wait;
}

__PACKAGE__->meta->make_immutable;

1;

__END__