.\" Automatically generated by Pod::Man 4.11 (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 .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MooseX::Daemonize::Core 3pm" .TH MooseX::Daemonize::Core 3pm "2019-12-22" "perl v5.30.0" "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" MooseX::Daemonize::Core \- A Role with the core daemonization features .SH "VERSION" .IX Header "VERSION" version 0.22 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package My::Daemon; \& use Moose; \& \& with \*(AqMooseX::Daemonize::Core\*(Aq; \& \& sub start { \& my $self = shift; \& # daemonize me ... \& $self\->daemonize; \& # return from the parent,... \& return unless $self\->is_daemon; \& # but continue on in the child (daemon) \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is the basic daemonization Role, it provides a few methods (see below) and the minimum features needed to properly daemonize your code. .SS "Important Notes" .IX Subsection "Important Notes" None of the methods in this role will exit the parent process for you, it only forks and detaches your child (daemon) process. It is your responsibility to exit the parent process in some way. .PP There is no \s-1PID\s0 or \s-1PID\s0 file management in this role, that is your responsibility (see some of the other roles in this distro for that). .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" .IP "\fIis_daemon (is =\fR rw, isa => Bool)>" 4 .IX Item "is_daemon (is = rw, isa => Bool)>" This attribute is used to signal if we are within the daemon process or not. .IP "\fIno_double_fork (is =\fR rw, isa => Bool)>" 4 .IX Item "no_double_fork (is = rw, isa => Bool)>" Setting this attribute to true will cause this method to not perform the typical double-fork, which is extra added protection from your process accidentally acquiring a controlling terminal. More information can be found above, and by Googling \*(L"double fork daemonize\*(R". .Sp If you the double-fork behavior off, you might want to enable the \&\fIignore_zombies\fR. .IP "\fIignore_zombies (is =\fR rw, isa => Bool)>" 4 .IX Item "ignore_zombies (is = rw, isa => Bool)>" Setting this attribute to a true value will result in setting the \f(CW$SIG{CHLD}\fR handler to \f(CW\*(C`IGNORE\*(C'\fR. This tells perl to clean up zombie processes. By default, and for the most part you don't \fIneed\fR it, only when you turn off the double fork behavior (with the \fIno_double_fork\fR attribute) do you sometimes want this behavior. .IP "\fIdont_close_all_files (is =\fR rw, isa => Bool)>" 4 .IX Item "dont_close_all_files (is = rw, isa => Bool)>" Setting this attribute to true will cause it to skip closing all the filehandles. This is useful if you are opening things like sockets and such in the pre-fork. .SH "METHODS" .IX Header "METHODS" .IP "\fBdaemon_fork (?%options)\fR" 4 .IX Item "daemon_fork (?%options)" This forks off the child process to be daemonized. Just as with the built in fork, it returns the child pid to the parent process, 0 to the child process. It will also set the is_daemon flag appropriately. .Sp The \f(CW%options\fR argument remains for backwards compatibility, but it is suggested that you use the attributes listed above instead. .IP "\fBdaemon_detach (?%options)\fR" 4 .IX Item "daemon_detach (?%options)" This detaches the new child process from the terminal by doing the following things. .Sp The \f(CW%options\fR argument remains for backwards compatibility, but it is suggested that you use the attributes listed above instead. .RS 4 .IP "Becomes a session leader" 4 .IX Item "Becomes a session leader" This detaches the program from the controlling terminal, it is accomplished by calling \f(CW\*(C`POSIX::setsid\*(C'\fR. .IP "Performing the double-fork" 4 .IX Item "Performing the double-fork" See below for information on how to change this part of the process. .ie n .IP "Changes the current working directory to ""/""" 4 .el .IP "Changes the current working directory to ``/''" 4 .IX Item "Changes the current working directory to /" This is standard daemon behavior, if you want a different working directory then simply change it later in your daemons code. .IP "Clears the file creation mask." 4 .IX Item "Clears the file creation mask." .PD 0 .IP "Closes all open file descriptors." 4 .IX Item "Closes all open file descriptors." .PD See the \fIdont_close_all_files\fR attribute for information on how to change this part of the process. .IP "Reopen \s-1STDERR, STDOUT & STDIN\s0 to /dev/null" 4 .IX Item "Reopen STDERR, STDOUT & STDIN to /dev/null" This behavior can be controlled slightly though the \f(CW\*(C`MX_DAEMON_STDERR\*(C'\fR and \f(CW\*(C`MX_DAEMON_STDOUT\*(C'\fR environment variables. It will look for a filename in either of these variables and redirect \f(CW\*(C`STDOUT\*(C'\fR and/or \f(CW\*(C`STDERR\*(C'\fR to those files. This is useful for debugging and/or testing purposes. .Sp \&\fB\s-1NOTE\s0\fR .Sp If called from within the parent process (the \f(CW\*(C`is_daemon\*(C'\fR flag is set to false), this method will simply return and do nothing. .IP "\fBdaemonize (?%options)\fR" 4 .IX Item "daemonize (?%options)" This will simply call \f(CW\*(C`daemon_fork\*(C'\fR followed by \f(CW\*(C`daemon_detach\*(C'\fR. .Sp The \f(CW%options\fR argument remains for backwards compatibility, but it is suggested that you use the attributes listed above instead. .IP "\fBmeta()\fR" 4 .IX Item "meta()" The \f(CW\*(C`meta()\*(C'\fR method from Class::MOP::Class .RE .RS 4 .RE .SH "STUFF YOU SHOULD READ" .IX Header "STUFF YOU SHOULD READ" .IP "Note about double fork" 4 .IX Item "Note about double fork" Taken from in a comment entitled \fIThe second fork _is_ necessary by Jonathan Bartlett\fR, it is not the definitive statement on the issue, but it's clear and well written enough so I decided to reproduce it here. .Sp .Vb 2 \& The first fork accomplishes two things \- allow the shell to return, \& and allow you to do a setsid(). \& \& The setsid() removes yourself from your controlling terminal. You \& see, before, you were still listed as a job of your previous process, \& and therefore the user might accidentally send you a signal. setsid() \& gives you a new session, and removes the existing controlling terminal. \& \& The problem is, you are now a session leader. As a session leader, if \& you open a file descriptor that is a terminal, it will become your \& controlling terminal (oops!). Therefore, the second fork makes you NOT \& be a session leader. Only session leaders can acquire a controlling \& terminal, so you can open up any file you wish without worrying that \& it will make you a controlling terminal. \& \& So \- first fork \- allow shell to return, and permit you to call setsid() \& \& Second fork \- prevent you from accidentally reacquiring a controlling \& terminal. .Ve .Sp That said, you don't always want this to be the behavior, so you are free to specify otherwise using the \fIno_double_fork\fR attribute. .IP "Note about zombies" 4 .IX Item "Note about zombies" Doing the double fork (see above) tends to get rid of your zombies since by the time you have double forked your daemon process is then owned by the init process. However, sometimes the double-fork is more than you really need, and you want to keep your daemon processes a little closer to you. In this case you have to watch out for zombies, you can avoid then by just setting the \fIignore_zombies\fR attribute (see above). .SH "ENVIRONMENT VARIABLES" .IX Header "ENVIRONMENT VARIABLES" These variables are best just used for debugging and/or testing, but not used for actual logging. For that, you should reopen \f(CW\*(C`STDOUT\*(C'\fR/\f(CW\*(C`STDERR\*(C'\fR on your own. .IP "\fB\s-1MX_DAEMON_STDOUT\s0\fR" 4 .IX Item "MX_DAEMON_STDOUT" A filename to redirect the daemon \f(CW\*(C`STDOUT\*(C'\fR to. .IP "\fB\s-1MX_DAEMON_STDERR\s0\fR" 4 .IX Item "MX_DAEMON_STDERR" A filename to redirect the daemon \f(CW\*(C`STDERR\*(C'\fR to. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" Moose::Role, \s-1POSIX\s0 .SH "INCOMPATIBILITIES" .IX Header "INCOMPATIBILITIES" .SH "SEE ALSO" .IX Header "SEE ALSO" Proc::Daemon .PP This code is based \fB\s-1HEAVILY\s0\fR on Proc::Daemon, we originally depended on it, but we needed some more flexibility, so instead we just stole the code. .SH "SUPPORT" .IX Header "SUPPORT" Bugs may be submitted through the \s-1RT\s0 bug tracker (or bug\-MooseX\-Daemonize@rt.cpan.org ). .PP There is also a mailing list available for users of this distribution, at . .PP There is also an irc channel available for users of this distribution, at \&\f(CW\*(C`#moose\*(C'\fR on \f(CW\*(C`irc.perl.org\*(C'\fR . .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Stevan Little .IP "\(bu" 4 Chris Prather .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2007 by Chris Prather. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .PP Portions heavily borrowed from Proc::Daemon which is copyright Earl Hood.