.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Net::Server::Daemonize 3pm" .TH Net::Server::Daemonize 3pm "2018-02-12" "perl v5.26.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Net::Server::Daemonize \- Safe fork and daemonization utilities .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Net::Server::Daemonize qw(daemonize); \& \& daemonize( \& \*(Aqnobody\*(Aq, # User \& \*(Aqnobody\*(Aq, # Group \& \*(Aq/var/state/mydaemon.pid\*(Aq # Path to PID file \- optional \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module is intended to let you simply and safely daemonize your server on systems supporting the \s-1POSIX\s0 module. This means that your Perl script runs in the background, and it's process \s-1ID\s0 is stored in a file so you can easily stop it later. .SH "EXPORTED FUNCTIONS" .IX Header "EXPORTED FUNCTIONS" .IP "daemonize" 4 .IX Item "daemonize" Main routine. Arguments are user (or userid), group (or group id or space delimited list of groups), and pid_file (path to file). This routine will check on the pid file, safely fork, create the pid file (storing the pid in the file), become another user and group, close \&\s-1STDIN, STDOUT\s0 and \s-1STDERR,\s0 separate from the process group (become session leader), and install \f(CW$SIG\fR{\s-1INT\s0} to remove the pid file. In otherwords \- daemonize. All errors result in a die. As of version 0.89 the pid_file is optional. .IP "safe_fork" 4 .IX Item "safe_fork" Block \s-1SIGINT\s0 during fork. No arguments. Returns pid of forked child. All errors result in a die. .IP "set_user" 4 .IX Item "set_user" Become another user and group. Arguments are user (or userid) and group (or group id or space delimited list of groups). .IP "set_uid" 4 .IX Item "set_uid" Become another user. Argument is user (or userid). All errors die. .IP "set_gid" 4 .IX Item "set_gid" Become another group. Arguments are groups (or group ids or space delimited list of groups or group ids). All errors die. .IP "get_uid" 4 .IX Item "get_uid" Find the uid. Argument is user (userid returns userid). Returns userid. All errors die. .IP "get_gid" 4 .IX Item "get_gid" Find the gids. Arguments are groups or space delimited list of groups. All errors die. .IP "is_root_user" 4 .IX Item "is_root_user" Determine if the process is running as root. Returns 1 or undef. .IP "check_pid_file" 4 .IX Item "check_pid_file" Arguments are pid_file (full path to pid_file). Checks for existence of pid_file. If file exists, open it and determine if the process that created it is still running. This is done first by checking for a /proc file system and second using a \*(L"ps\*(R" command (\s-1BSD\s0 syntax). (If neither of these options exist it assumed that the process has ended) If the process is still running, it aborts. Otherwise, returns true. All errors die. .IP "create_pid_file." 4 .IX Item "create_pid_file." Arguments are pid_file (full path to pid_file). Calls check_pid_file. If it is successful (no pid_file exists), creates a pid file and stores $$ in the file. .IP "unlink_pid_file" 4 .IX Item "unlink_pid_file" Does just that. .SH "SEE ALSO" .IX Header "SEE ALSO" Net::Server. Net::Daemon, The Perl Cookbook Recipe 17.15. .SH "AUTHORS" .IX Header "AUTHORS" Jeremy Howard .PP Program flow, concepts and initial work. .PP Paul Seamons .PP Code rework and componentization. Ongoing maintainer. .SH "LICENSE" .IX Header "LICENSE" .Vb 4 \& This package may be distributed under the terms of either the \& GNU General Public License \& or the \& Perl Artistic License \& \& All rights reserved. .Ve