App-Daemon
view release on metacpan or search on metacpan
@ARGV and can be checked in $opts{k}, $opts{P}, and $opts{U}.
Gotchas
Log File Permissions
If the process is started as root but later drops permissions to a
non-priviledged user for security purposes, it's important that
logfiles are created with correct permissions.
If they're created as root when the program starts, the
non-priviledged user won't be able to write to them later (unless
they're world-writable which is also undesirable because of security
concerns).
The best strategy to handle this case is to specify the
non-priviledged user as the owner of the logfile in the Log4perl
configuration:
log4perl.logger = DEBUG, FileApp
log4perl.appender.FileApp = Log::Log4perl::Appender::File
log4perl.appender.FileApp.filename = /var/log/foo-app.log
log4perl.appender.FileApp.owner = nobody
log4perl.appender.FileApp.layout = PatternLayout
log4perl.appender.FileApp.layout.ConversionPattern = %d %m%n
This way, the process starts up as root, creates the logfile if it
doesn't exist yet, and changes its owner to 'nobody'. Later, when
the process assumes the identity of the user 'nobody', it will
continue to write to the logfile without permission problems.
Log4perl Categories
Note that App::Daemon is logging messages in Log4perl's App::Daemon
namespace. So, if you're running your own Log4perl configuration and
define a root logger like
log4perl.logger=DEBUG, appendername
then App::Daemon's messages will bubble up to it and be visible in
the output. If you don't want that, either use
log4perl.logger.My.App=DEBUG, appendername
to explicitly enable verbose logging in your application namespace
(and not in App::Daemon's) or tone down App::Daemon's verbosity via
log4perl.logger.App.Daemon=ERROR
explicitly. If you want more details on basic Log4perl features,
check out the Log::Log4perl manual page.
Detach only
If you want to create a daemon without the fancy command line parsing
and PID file checking functions, use
use App::Daemon qw(detach);
detach();
# ... some code here
This will fork a child, terminate the parent and detach the child from
the terminal. Issued from the command line, the program above will
continue to run the code following the detach() call but return to the
shell prompt immediately.
AUTHOR
2008, Mike Schilli <cpan@perlmeister.com>
LICENSE
Copyright 2008-2012 by Mike Schilli, all rights reserved. This program
is free software, you can redistribute it and/or modify it under the
same terms as Perl itself.
( run in 0.913 second using v1.01-cache-2.11-cpan-6aa56a78535 )