Daemonise

 view release on metacpan or  search on metacpan

examples/dungeonkeeper  view on Meta::CPAN

    my (@daemons) = @_;

    # TODO: handle starting of individual bunnies

    $d->is_worker(1);

    # create PID dir and ensure correct owner/group/permissions
    mkdir($d->pid_dir, 0755) unless (-d $d->pid_dir);
    my (undef, undef, $uid) = getpwnam($d->user);
    my (undef, undef, $gid) = getgrnam($d->group);
    chown($uid, $gid, $d->pid_dir) if ($uid or $gid);

    die("not a directory: " . $d->bin_dir) unless (-d $d->bin_dir);

    $d->start(\&main);

    return;
}

sub stop {
    my (@daemons) = @_;

lib/Daemonise/Plugin/Daemon.pm  view on Meta::CPAN


    ### parent process should do the pid file and exit
    if ($pid) {
        $pid && exit;
        ### child process will continue on
    }
    else {
        $self->_create_pid_file if $self->has_pid_file;

        ### make sure we can remove the file later
        chown($self->uid, $self->gid, $self->pid_file)
            if $self->has_pid_file;

        ### become another user and group
        $self->_set_user;

        ### close all input/output and separate
        ### from the parent process group
        open(STDIN, '<', '/dev/null')
            or die "Can't open STDIN from /dev/null: [$!]";



( run in 2.250 seconds using v1.01-cache-2.11-cpan-71847e10f99 )