.\" 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 3pm" .TH MooseX::Daemonize 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 \- Role for daemonizing your Moose based application .SH "VERSION" .IX Header "VERSION" version 0.22 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package My::Daemon; \& use Moose; \& \& with qw(MooseX::Daemonize); \& \& # ... define your class .... \& \& after start => sub { \& my $self = shift; \& return unless $self\->is_daemon; \& # your daemon code here ... \& }; \& \& # then in your script ... \& \& my $daemon = My::Daemon\->new_with_options(); \& \& my ($command) = @{$daemon\->extra_argv} \& defined $command || die "No command specified"; \& \& $daemon\->start if $command eq \*(Aqstart\*(Aq; \& $daemon\->status if $command eq \*(Aqstatus\*(Aq; \& $daemon\->restart if $command eq \*(Aqrestart\*(Aq; \& $daemon\->stop if $command eq \*(Aqstop\*(Aq; \& \& warn($daemon\->status_message); \& exit($daemon\->exit_code); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Often you want to write a persistent daemon that has a pid file, and responds appropriately to Signals. This module provides a set of basic roles as an infrastructure to do that. .SH "WARNING" .IX Header "WARNING" The maintainers of this module now recommend using Daemon::Control instead. .SH "CAVEATS" .IX Header "CAVEATS" When going into background MooseX::Daemonize closes all open file handles. This may interfere with you logging because it may also close the log file handle you want to write to. To prevent this you can either defer opening the log file until after start. Alternatively, use can use the \&'dont_close_all_files' option either from the command line or in your .sh script. .PP Assuming you want to use Log::Log4perl for example you could expand the MooseX::Daemonize example above like this. .PP .Vb 8 \& after start => sub { \& my $self = shift; \& return unless $self\->is_daemon; \& Log::Log4perl\->init(\e$log4perl_config); \& my $logger = Log::Log4perl\->get_logger(); \& $logger\->info("Daemon started"); \& # your daemon code here ... \& }; .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" This list includes attributes brought in from other roles as well we include them here for ease of documentation. All of these attributes are settable though MooseX::Getopt's command line handling, with the exception of \f(CW\*(C`is_daemon\*(C'\fR. .IP "\fIprogname Path::Class::Dir | Str\fR" 4 .IX Item "progname Path::Class::Dir | Str" The name of our daemon, defaults to \f(CW\*(C`$package_name =~ s/::/_/\*(C'\fR; .IP "\fIpidbase Path::Class::Dir | Str\fR" 4 .IX Item "pidbase Path::Class::Dir | Str" The base for our \s-1PID,\s0 defaults to \f(CW\*(C`/var/run/\*(C'\fR .IP "\fIbasedir Path::Class::Dir | Str\fR" 4 .IX Item "basedir Path::Class::Dir | Str" The directory we chdir to; defaults to \f(CW\*(C`/\*(C'\fR. .IP "\fIpidfile MooseX::Daemonize::Pid::File | Str\fR" 4 .IX Item "pidfile MooseX::Daemonize::Pid::File | Str" The file we store our \s-1PID\s0 in, defaults to \f(CW\*(C`$pidbase/$progname.pid\*(C'\fR .IP "\fIforeground Bool\fR" 4 .IX Item "foreground Bool" If true, the process won't background. Useful for debugging. This option can be set via Getopt's \-f. .IP "\fIno_double_fork Bool\fR" 4 .IX Item "no_double_fork Bool" If true, the process will not perform the typical double-fork, which is extra added protection from your process accidentally acquiring a controlling terminal. More information can be found by Googling \*(L"double fork daemonize\*(R". .IP "\fIignore_zombies Bool\fR" 4 .IX Item "ignore_zombies Bool" If true, the process will not clean up zombie processes. Normally you don't want this. .IP "\fIdont_close_all_files Bool\fR" 4 .IX Item "dont_close_all_files Bool" If true, the objects open filehandles will not be closed when daemonized. Normally you don't want this. .IP "\fIis_daemon Bool\fR" 4 .IX Item "is_daemon Bool" If true, the process is the backgrounded daemon process, if false it is the parent process. This is useful for example in an \f(CW\*(C`after \*(Aqstart\*(Aq =\*(C'\fR sub { }> block. .Sp \&\fB\s-1NOTE:\s0\fR This option is explicitly \fBnot\fR available through MooseX::Getopt. .IP "\fIstop_timeout\fR" 4 .IX Item "stop_timeout" Number of seconds to wait for the process to stop, before trying harder to kill it. Defaults to 2 seconds. .PP These are the internal attributes, which are not available through MooseX::Getopt. .IP "\fIexit_code Int\fR" 4 .IX Item "exit_code Int" .PD 0 .IP "\fIstatus_message Str\fR" 4 .IX Item "status_message Str" .PD .SH "METHODS" .IX Header "METHODS" .SS "Daemon Control Methods" .IX Subsection "Daemon Control Methods" These methods can be used to control the daemon behavior. Every effort has been made to have these methods \s-1DWIM\s0 (Do What I Mean), so that you can focus on just writing the code for your daemon. .PP Extending these methods is best done with the Moose method modifiers, such as \f(CW\*(C`before\*(C'\fR, \f(CW\*(C`after\*(C'\fR and \f(CW\*(C`around\*(C'\fR. .IP "\fBstart\fR" 4 .IX Item "start" Setup a pidfile, fork, then setup the signal handlers. .IP "\fBstop\fR" 4 .IX Item "stop" Stop the process matching the pidfile, and unlinks the pidfile. .IP "\fBrestart\fR" 4 .IX Item "restart" Literally this is: .Sp .Vb 2 \& $self\->stop(); \& $self\->start(); .Ve .IP "\fBstatus\fR" 4 .IX Item "status" .PD 0 .IP "\fBshutdown\fR" 4 .IX Item "shutdown" .PD .SS "Pidfile Handling Methods" .IX Subsection "Pidfile Handling Methods" .IP "\fBinit_pidfile\fR" 4 .IX Item "init_pidfile" This method will create a MooseX::Daemonize::Pid::File object and tell it to store the \s-1PID\s0 in the file \f(CW\*(C`$pidbase/$progname.pid\*(C'\fR. .IP "\fBcheck\fR" 4 .IX Item "check" This checks to see if the daemon process is currently running by checking the pidfile. .IP "\fBget_pid\fR" 4 .IX Item "get_pid" Returns the \s-1PID\s0 of the daemon process. .IP "\fBsave_pid\fR" 4 .IX Item "save_pid" Write the pidfile. .IP "\fBremove_pid\fR" 4 .IX Item "remove_pid" Removes the pidfile. .SS "Signal Handling Methods" .IX Subsection "Signal Handling Methods" .IP "\fBsetup_signals\fR" 4 .IX Item "setup_signals" Setup the signal handlers, by default it only sets up handlers for \s-1SIGINT\s0 and \&\s-1SIGHUP.\s0 If you wish to add more signals just use the \f(CW\*(C`after\*(C'\fR method modifier and add them. .IP "\fBhandle_sigint\fR" 4 .IX Item "handle_sigint" Handle a \s-1INT\s0 signal, by default calls \f(CW\*(C`$self\-\*(C'\fR\fBstop()\fR> .IP "\fBhandle_sighup\fR" 4 .IX Item "handle_sighup" Handle a \s-1HUP\s0 signal. By default calls \f(CW\*(C`$self\-\*(C'\fR\fBrestart()\fR> .SS "Exit Code Methods" .IX Subsection "Exit Code Methods" These are overridable constant methods used for setting the exit code. .IP "\s-1OK\s0" 4 .IX Item "OK" Returns 0. .IP "\s-1ERROR\s0" 4 .IX Item "ERROR" Returns 1. .SS "Introspection" .IX Subsection "Introspection" .IP "\fBmeta()\fR" 4 .IX Item "meta()" The \f(CW\*(C`meta()\*(C'\fR method from Class::MOP::Class .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" Moose, MooseX::Getopt, MooseX::Types::Path::Class and \s-1POSIX\s0 .SH "INCOMPATIBILITIES" .IX Header "INCOMPATIBILITIES" Obviously this will not work on Windows. .SH "SEE ALSO" .IX Header "SEE ALSO" Daemon::Control, Proc::Daemon, Daemon::Generic .SH "THANKS" .IX Header "THANKS" Mike Boyko, Matt S. Trout, Stevan Little, Brandon Black, Ash Berlin and the #moose denizens .PP Some bug fixes sponsored by Takkle Inc. .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 "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Karen Etheridge .IP "\(bu" 4 Michael Reddick .IP "\(bu" 4 Yuval Kogman .IP "\(bu" 4 Ash Berlin .IP "\(bu" 4 Brandon L Black .IP "\(bu" 4 Jonathan Sailor .IP "\(bu" 4 David Steinbrunner .IP "\(bu" 4 Michael Schwern .IP "\(bu" 4 Shoichi Kaji .IP "\(bu" 4 Dave Rolsky .IP "\(bu" 4 Chisel Wright .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.