|Syntactic Confectionery Delight|
A few questions regarding Proc::Daemonby walkingthecow (Friar)
|on Nov 07, 2013 at 23:10 UTC||Need Help??|
walkingthecow has asked for the
wisdom of the Perl Monks concerning the following question:
Good afternoon monks! Before I ever resort to asking for help, I always try my best to do my own research and figure things out myself. I am running into a wall here simply because the ways in which is Proc::Daemon used are so wildly different, and the CPAN documentation is rather limited.
Before I go further with my questions, I will give you a chance to see the code I have thus far written:
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.
Second, I am handling SIGNALS myself, but I am wondering if Proc::Daemon handles that for me, or if there is a method of doing so with Proc::Daemon. I feel that I am using mixed methods here (i.e., how to do it without Proc::Daemon mixed with the way it is done with Proc::Daemon). Basically, I'd like for the script to die gracefully (close filehandles, remove pid file, etc) on any signal or an ARGV of stop, and I'd like for the daemon to give a status report (i.e., "divinityd runnin (PID#)" when someone does './divinityd status'. Below is the code I was using to check status, stop, etc...
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.
Basically, I am just wondering what aspects of what I am doing are just completely wrong. Where I am wrong, and possibly if anyone knows any good newer resources on how to use Proc::Daemon.
Thanks in advance monks for any help you can give me and have a wonderful day!
My apologies for answering my own question, or at least it seems that I am getting there anyway. I noticed that Proc::Daemon documentation says:
6. The second child closes all open file descriptors (unless you define dont_close_fh and/or dont_close_fd
So, moving my code around a bit I add the log file after Proc::Daemon::Init(); However, I am still trying to figure out how to take a command line 'stop' or 'status' and have the logging work outside of my 'while ( $keep_going )' loop. If/when I figure that out, I will post updated code.