|
NAMEMooseX::Daemonize - Role for daemonizing your Moose based applicationVERSIONversion 0.22SYNOPSISpackage 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 'start'; $daemon->status if $command eq 'status'; $daemon->restart if $command eq 'restart'; $daemon->stop if $command eq 'stop'; warn($daemon->status_message); exit($daemon->exit_code); DESCRIPTIONOften 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.WARNINGThe maintainers of this module now recommend using Daemon::Control instead.CAVEATSWhen 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.Assuming you want to use Log::Log4perl for example you could expand the MooseX::Daemonize example above like this. after start => sub { my $self = shift; return unless $self->is_daemon; Log::Log4perl->init(\$log4perl_config); my $logger = Log::Log4perl->get_logger(); $logger->info("Daemon started"); # your daemon code here ... }; ATTRIBUTESThis 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 "is_daemon".
These are the internal attributes, which are not available through MooseX::Getopt.
METHODSDaemon Control MethodsThese methods can be used to control the daemon behavior. Every effort has been made to have these methods DWIM (Do What I Mean), so that you can focus on just writing the code for your daemon.Extending these methods is best done with the Moose method modifiers, such as "before", "after" and "around".
Pidfile Handling Methods
Signal Handling Methods
Exit Code MethodsThese are overridable constant methods used for setting the exit code.
Introspection
DEPENDENCIESMoose, MooseX::Getopt, MooseX::Types::Path::Class and POSIXINCOMPATIBILITIESObviously this will not work on Windows.SEE ALSODaemon::Control, Proc::Daemon, Daemon::GenericTHANKSMike Boyko, Matt S. Trout, Stevan Little, Brandon Black, Ash Berlin and the #moose denizensSome bug fixes sponsored by Takkle Inc. SUPPORTBugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Daemonize> (or bug-MooseX-Daemonize@rt.cpan.org <mailto:bug-MooseX-Daemonize@rt.cpan.org>).There is also a mailing list available for users of this distribution, at <http://lists.perl.org/list/moose.html>. There is also an irc channel available for users of this distribution, at "#moose" on "irc.perl.org" <irc://irc.perl.org/#moose>. AUTHORS
CONTRIBUTORS
COPYRIGHT AND LICENCEThis software is copyright (c) 2007 by Chris Prather.This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Visit the GSP FreeBSD Man Page Interface. |