Now, as it stands at this point, when I run my daemon (as root, with sudo, or as a regular user), then do a 'ps -ef | grep perl', I see that my daemon is not running, and nothing has been logged. However, when I comment out the daemon aspect of the script, everything seems to work as expected. So, first, I am not sure why it's not daemonizing.#!/usr/bin/env perl use strict; use warnings; use POSIX; use Proc::Daemon; use Proc::PID::File; use Log::Dispatch; use Log::Dispatch::File; use Config::General; use Sys::Hostname; use Data::Dumper; use File::Spec; my $config_file = '/etc/divinity/divinityd.conf'; # First we deal with config file and command line options # Command line options override config file. my $conf = Config::General->new($config_file); my %config = $conf->getall; my $pid_file = $config{pid_file} || '/var/run/divinityd.pid'; my $hostname = hostname; # First we deal with required config options my $method = $config{method} or config_err("no method specified"); my ($server_url,$validation_key,$scp_host,$log_file,$log_level); if ( $method eq "https" ) { $server_url = $config{server_url} or config_err("no server_url spe +cified"); $validation_key = $config{validation_key} or config_err("no valida +tion_key specified"); } if ( $method eq "scp" ) { $scp_host = $config{scp_host} or config_err("no scp_host specified +"); } my $node_name = $config{node_name} || $hostname; my $user = $config{user} || 'divinityd'; my $group = $config{group} || 'divinityd'; my $logging = $config{logging} || 'on'; if ( $logging eq "on" ) { $log_file = $config{log_file} || '/var/log/divinityd.log'; $log_level = $config{log_level} || 'warning'; } my $fork = $config{fork} || 'yes'; my $child_num = $config{child_num} || 10; my $proxy = $config{proxy} || $ENV{PROXY}; my $interval = $config{interval} || '300'; my $log = Log::Dispatch->new( callbacks => sub { my %h=@_; return "[".strftime("%F %R", localtime(time))."] " .$hostname." ".$h{message}."\n"; } ); $log->add( Log::Dispatch::File->new( name => 'divinityd_log', min_level => $log_level, mode => 'append', filename => $log_file, ) ); # # Setup signal handlers so that we have time to cleanup before shuttin +g down # my $keep_going = 1; $SIG{HUP} = sub { $log->warning("Caught SIGHUP: exiting gracefully"); $keep_going = 0; }; $SIG{INT} = sub { $log->warning("Caught SIGINT: exiting gracefully"); $keep_going = 0; }; $SIG{QUIT} = sub { $log->warning("Caught SIGQUIT: exiting gracefully"); $keep_going = 0; }; my $daemon = Proc::Daemon->new( pid_file => $pid_file, ); $daemon->Init; while ( $keep_going ) { $log->warning("TEST\n"); sleep(5); } sub config_err { my $message = $_[0]; print STDERR $message; die("\n"); } sub dienice ($) { my ($package, $filename, $line) = caller; $log->critical("$_[0] at line $line in $filename"); die $_[0]; }
The problem I was running into here was that when one would check the status of the daemon, the pid file had already been created, thus the status would say running, even if the daemon wasn't actually running.my $daemon = Proc::Daemon->new( pid_file => $pid_file, ); $daemon->Init; if ( $ARGV[0] eq "stop ) { $daemon->Kill_Daemon(); } elsif ( $ARGV[0] eq "status" ) { $daemon->Status($pid_file); } elsif ( $ARGV[0] eq "start" ) { while ( $keep_going ) { $log->warning("TEST\n"); sleep(5); } }
In reply to A few questions regarding Proc::Daemon by walkingthecow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |