Commit 62a0af8d authored by Salvatore Bonaccorso's avatar Salvatore Bonaccorso

Imported Upstream version 0.20

parent 7d75ebd8
Revision history for Perl extension App::Daemon.
0.20 (11/11/2013)
(ms) [rt.cpan.org #61428] Fixed bug in detach() which no longer attempts
to write to a non-existing pid file.
0.19 (07/07/2013)
(ms) [rt.cpan.org #86762] Peter noticed that App::Daemon's fork()
check was incorrect. Fixed.
......
......@@ -2,7 +2,7 @@ package App::Daemon;
use strict;
use warnings;
our $VERSION = '0.19';
our $VERSION = '0.20';
use Getopt::Std;
use Pod::Usage;
......@@ -233,9 +233,11 @@ sub detach {
# process group leader of a new process group.
POSIX::setsid();
INFO "Process ID is $$";
pid_file_write($$);
INFO "Written to $pidfile";
if( defined $pidfile ) {
INFO "Process ID is $$";
pid_file_write($$);
INFO "Written to $pidfile";
}
if($as_user) {
user_switch();
......@@ -416,7 +418,8 @@ sub pid_file_read {
my $pid = <FILE>;
chomp $pid if defined $pid;
close FILE;
return $pid;
$pid =~ /^(\d+)$/; # Untaint
return $1;
}
###########################################
......@@ -700,6 +703,10 @@ After this, options C<-k>, C<-P>, and C<-U> will have disappeared from
=head2 Gotchas
=over 4
=item 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.
......@@ -723,6 +730,29 @@ 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.
=item 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 L<Log::Log4perl> manual page.
=back
=head2 Detach only
If you want to create a daemon without the fancy command line parsing
......
......@@ -13,5 +13,6 @@ t/001Basic.t
t/002Params.t
t/003CmdLine.t
t/004Pidfile.t
t/005Detach.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
......@@ -4,7 +4,7 @@
"Mike Schilli <m@perlmeister.com>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120351",
"generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.132140",
"license" : [
"unknown"
],
......@@ -49,5 +49,5 @@
"url" : "http://github.com/mschilli/app-daemon"
}
},
"version" : "0.19"
"version" : "0.20"
}
......@@ -7,7 +7,7 @@ build_requires:
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120351'
generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.132140'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
......@@ -28,4 +28,4 @@ requires:
Test::More: 0
resources:
repository: http://github.com/mschilli/app-daemon
version: 0.19
version: 0.20
######################################################################
App::Daemon 0.19
App::Daemon 0.20
######################################################################
NAME
......@@ -209,28 +209,51 @@ DESCRIPTION
@ARGV and can be checked in $opts{k}, $opts{P}, and $opts{U}.
Gotchas
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.
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
......
#!/usr/local/bin/perl -w
use strict;
my( $done_file ) = @ARGV;
die "usage: $0 done_file" if !defined $done_file;
# Program:
use App::Daemon qw( detach );
detach();
sleep(5);
sleep(1);
open FILE, ">foo.txt" or die;
print FILE "Waaah!\n";
open FILE, ">", $done_file or die;
print FILE "Done\n";
close FILE;
# launch app-daemon
use File::Temp qw(tempfile);
use FindBin qw($Bin);
use Sysadm::Install qw(:all);
use Test::More;
use App::Daemon;
use Log::Log4perl qw(:easy);
# Log::Log4perl->easy_init($DEBUG);
plan tests => 2;
my( $fh, $tmpfile ) = tempfile( UNLINK => 1 );
my ( $stdout, $stderr, $rc );
my @cmdline = ( $^X, "-I$Bin/../blib/lib", "$Bin/../eg/test-detach",
$tmpfile);
( $stdout, $stderr, $rc ) = tap @cmdline;
is $rc, 0, "detached process started";
for( 1 .. 10 ) {
my $data = slurp $tmpfile;
if( $data =~ /Done/ ) {
ok 1, "detached process finished";
last;
}
sleep 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment