diff options
author | ivan <ivan> | 2010-06-16 21:53:24 +0000 |
---|---|---|
committer | ivan <ivan> | 2010-06-16 21:53:24 +0000 |
commit | 7ea8e16cf847c607bf917cb3b31110d18104a343 (patch) | |
tree | b0663a3c412b0df9763a0ff547ed30b3b62f72e5 /FS/FS/Daemon.pm | |
parent | 0743ea91445e0682a00a05a0ae8f72e587d6a0e9 (diff) |
a local XML-RPC server for ncic: daemonize and respond to TERM, RT#7780
Diffstat (limited to 'FS/FS/Daemon.pm')
-rw-r--r-- | FS/FS/Daemon.pm | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/FS/FS/Daemon.pm b/FS/FS/Daemon.pm index 38e6d7577..b58cde49f 100644 --- a/FS/FS/Daemon.pm +++ b/FS/FS/Daemon.pm @@ -6,6 +6,8 @@ use Exporter; use Fcntl qw(:flock); use POSIX qw(setsid); use IO::File; +use File::Basename; +use File::Slurp qw(slurp); use Date::Format; #this is a simple refactoring of the stuff from freeside-queued, just to @@ -20,11 +22,18 @@ use Date::Format; $pid_dir = '/var/run'; $NOSIG = 0; +$PID_NEWSTYLE = 0; sub daemonize1 { $me = shift; - $pid_file = "$pid_dir/$me"; + $pid_file = $pid_dir; + if ( $PID_NEWSTYLE ) { + $pid_file .= '/freeside'; + mkdir $pid_file unless -d $pid_file; + chown $FS::UID::freeside_uid, -1, $pid_file; + } + $pid_file .= "/$me"; $pid_file .= '.'.shift if scalar(@_); $pid_file .= '.pid'; @@ -35,6 +44,7 @@ sub daemonize1 { print "$me started with pid $pid\n"; #logging to $log_file\n"; exit unless $pid_file; my $pidfh = new IO::File ">$pid_file" or exit; + chown $FS::UID::freeside_uid, -1, $pid_file; print $pidfh "$pid\n"; exit; } @@ -82,14 +92,18 @@ sub sigterm { $sigterm; } sub logfile { $logfile = shift; } #_logmsg('test'); } sub myexit { - unlink $pid_file if -e $pid_file; + chomp( my $pid = slurp($pid_file) ); + unlink $pid_file if -e $pid_file && $$ == $pid; exit; } sub _die { die @_ if $^S; # $^S = 1 during an eval(), don't break exception handling my $msg = shift; - unlink $pid_file if -e $pid_file; + + chomp( my $pid = slurp($pid_file) ); + unlink $pid_file if -e $pid_file && $$ == $pid; + _logmsg($msg); } |