Commit d5b02ea1 authored by Salvatore Bonaccorso's avatar Salvatore Bonaccorso

Imported Upstream version 0.21

parent 62a0af8d
Revision history for Perl extension App::Daemon. Revision history for Perl extension App::Daemon.
0.21 (04/28/2014)
(ms) Nicolai Langfeldt added -g option to switch to specified group
when app was started as root.
(ms) Makefile.PL now dies on Win32 to save the CPAN smoke testers
some grief with hanging tests ([rt.cpan.org #81980])
0.20 (11/11/2013) 0.20 (11/11/2013)
(ms) [rt.cpan.org #61428] Fixed bug in detach() which no longer attempts (ms) [rt.cpan.org #61428] Fixed bug in detach() which no longer attempts
to write to a non-existing pid file. to write to a non-existing pid file.
......
...@@ -2,7 +2,7 @@ package App::Daemon; ...@@ -2,7 +2,7 @@ package App::Daemon;
use strict; use strict;
use warnings; use warnings;
our $VERSION = '0.20'; our $VERSION = '0.21';
use Getopt::Std; use Getopt::Std;
use Pod::Usage; use Pod::Usage;
...@@ -22,7 +22,7 @@ use constant LSB_NOT_RUNNING => 3; ...@@ -22,7 +22,7 @@ use constant LSB_NOT_RUNNING => 3;
use constant LSB_UNKNOWN => 4; use constant LSB_UNKNOWN => 4;
use constant ALREADY_RUNNING => 150; use constant ALREADY_RUNNING => 150;
our ($pidfile, $logfile, $l4p_conf, $as_user, $background, our ($pidfile, $logfile, $l4p_conf, $as_user, $as_group, $background,
$loglevel, $action, $appname, $default_pid_dir, $default_log_dir); $loglevel, $action, $appname, $default_pid_dir, $default_log_dir);
$action = ""; $action = "";
$appname = appname(); $appname = appname();
...@@ -66,9 +66,17 @@ sub cmd_line_parse { ...@@ -66,9 +66,17 @@ sub cmd_line_parse {
$as_user ||= 'nobody'; $as_user ||= 'nobody';
} }
if(my $_as_group = find_option('-g', 1)) {
$as_group = $_as_group;
}
else {
$as_group ||= 'nogroup';
}
if($> != 0) { if($> != 0) {
# Not root? Then we're ourselves # Not root? Then we're ourselves
($as_user) = getpwuid($>); ($as_user) = getpwuid($>);
($as_group) = getgrgid(POSIX::getgid());
} }
$background = 1 if(!defined $background); $background = 1 if(!defined $background);
...@@ -177,6 +185,8 @@ sub daemonize { ...@@ -177,6 +185,8 @@ sub daemonize {
if( $background ) { if( $background ) {
detach( $as_user ); detach( $as_user );
} elsif ($as_user) {
id_switch();
} }
my $prev_sig = $SIG{__DIE__}; my $prev_sig = $SIG{__DIE__};
...@@ -240,7 +250,7 @@ sub detach { ...@@ -240,7 +250,7 @@ sub detach {
} }
if($as_user) { if($as_user) {
user_switch(); id_switch();
} }
# close std file descriptors # close std file descriptors
...@@ -260,10 +270,20 @@ sub detach { ...@@ -260,10 +270,20 @@ sub detach {
} }
########################################### ###########################################
sub user_switch { sub id_switch {
########################################### ###########################################
if($> == 0) { if($> == 0) {
# If we're root, become the user set as 'as_user'; # If we're root, become user set as 'as_user' and the group in
# 'as_group'.
# Set the group first because it only works when still root
my ($group,undef,$gid) = getgrnam($as_group);
if(! defined $group) {
LOGDIE "Cannot switch to group $as_group";
}
POSIX::setgid($gid);
my ($name,$passwd,$uid) = getpwnam($as_user); my ($name,$passwd,$uid) = getpwnam($as_user);
if(! defined $name) { if(! defined $name) {
LOGDIE "Cannot switch to user $as_user"; LOGDIE "Cannot switch to user $as_user";
...@@ -639,6 +659,10 @@ to somewhere within C</var/log> for production use. ...@@ -639,6 +659,10 @@ to somewhere within C</var/log> for production use.
User to run as if started as root. Defaults to 'nobody'. User to run as if started as root. Defaults to 'nobody'.
=item -g as_group
Group to run as if started as root. Defaults to 'nogroup'.
=item -l4p l4p.conf =item -l4p l4p.conf
Path to Log4perl configuration file. Note that in this case the -v option Path to Log4perl configuration file. Note that in this case the -v option
...@@ -674,6 +698,7 @@ variables: ...@@ -674,6 +698,7 @@ variables:
$App::Daemon::l4p_conf = "myconf.l4p"; $App::Daemon::l4p_conf = "myconf.l4p";
$App::Daemon::background = 1; $App::Daemon::background = 1;
$App::Daemon::as_user = "nobody"; $App::Daemon::as_user = "nobody";
$App::Daemon::as_group = "nogroup";
use Log::Log4perl qw(:levels); use Log::Log4perl qw(:levels);
$App::Daemon::loglevel = $DEBUG; $App::Daemon::loglevel = $DEBUG;
......
...@@ -14,5 +14,4 @@ t/002Params.t ...@@ -14,5 +14,4 @@ t/002Params.t
t/003CmdLine.t t/003CmdLine.t
t/004Pidfile.t t/004Pidfile.t
t/005Detach.t t/005Detach.t
META.yml Module YAML meta-data (added by MakeMaker) META.yml Module meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
{
"abstract" : "Start an Application as a Daemon",
"author" : [
"Mike Schilli <m@perlmeister.com>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.132140",
"license" : [
"unknown"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "App-Daemon",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"File::Basename" : "0",
"File::Pid" : "0",
"File::Temp" : "0",
"Getopt::Std" : "0",
"Log::Log4perl" : "1.0",
"Pod::Usage" : "0",
"Sysadm::Install" : "0.37",
"Test::More" : "0"
}
}
},
"release_status" : "stable",
"resources" : {
"repository" : {
"url" : "http://github.com/mschilli/app-daemon"
}
},
"version" : "0.20"
}
--- --- #YAML:1.0
abstract: 'Start an Application as a Daemon' name: App-Daemon
version: 0.21
abstract: Start an Application as a Daemon
author: author:
- 'Mike Schilli <m@perlmeister.com>' - Mike Schilli <m@perlmeister.com>
build_requires: license: unknown
ExtUtils::MakeMaker: 0 distribution_type: module
configure_requires: configure_requires:
ExtUtils::MakeMaker: 0 ExtUtils::MakeMaker: 0
dynamic_config: 1 build_requires:
generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.132140' ExtUtils::MakeMaker: 0
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: App-Daemon
no_index:
directory:
- t
- inc
requires: requires:
File::Basename: 0 File::Basename: 0
File::Pid: 0 File::Pid: 0
File::Temp: 0 File::Temp: 0
Getopt::Std: 0 Getopt::Std: 0
Log::Log4perl: 1.0 Log::Log4perl: 1.0
Pod::Usage: 0 Pod::Usage: 0
Sysadm::Install: 0.37 Sysadm::Install: 0.37
Test::More: 0 Test::More: 0
resources: resources:
repository: http://github.com/mschilli/app-daemon repository: http://github.com/mschilli/app-daemon
version: 0.20 no_index:
directory:
- t
- inc
generated_by: ExtUtils::MakeMaker version 6.57_05
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
...@@ -10,6 +10,10 @@ my $meta_merge = { ...@@ -10,6 +10,10 @@ my $meta_merge = {
} }
}; };
if( $^O eq "MSWin32" ) {
die "$^O: OS unsupported";
}
WriteMakefile( WriteMakefile(
NAME => 'App::Daemon', NAME => 'App::Daemon',
VERSION_FROM => 'Daemon.pm', # finds $VERSION VERSION_FROM => 'Daemon.pm', # finds $VERSION
......
###################################################################### ######################################################################
App::Daemon 0.20 App::Daemon 0.21
###################################################################### ######################################################################
NAME NAME
...@@ -156,6 +156,9 @@ DESCRIPTION ...@@ -156,6 +156,9 @@ DESCRIPTION
-u as_user -u as_user
User to run as if started as root. Defaults to 'nobody'. User to run as if started as root. Defaults to 'nobody'.
-g as_group
Group to run as if started as root. Defaults to 'nogroup'.
-l4p l4p.conf -l4p l4p.conf
Path to Log4perl configuration file. Note that in this case the -v Path to Log4perl configuration file. Note that in this case the -v
option will be ignored. option will be ignored.
...@@ -182,6 +185,7 @@ DESCRIPTION ...@@ -182,6 +185,7 @@ DESCRIPTION
$App::Daemon::l4p_conf = "myconf.l4p"; $App::Daemon::l4p_conf = "myconf.l4p";
$App::Daemon::background = 1; $App::Daemon::background = 1;
$App::Daemon::as_user = "nobody"; $App::Daemon::as_user = "nobody";
$App::Daemon::as_group = "nogroup";
use Log::Log4perl qw(:levels); use Log::Log4perl qw(:levels);
$App::Daemon::loglevel = $DEBUG; $App::Daemon::loglevel = $DEBUG;
......
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