Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: A few questions regarding Proc::Daemon

by afoken (Parson)
on Nov 08, 2013 at 09:09 UTC ( #1061682=note: print w/ replies, xml ) Need Help??


in reply to A few questions regarding Proc::Daemon

Have a look at daemontools. Essentially, daemontools take care of start, stop, restart, logging, sending signals, "becoming a daemon". You don't have to reinvent all of this. Just write the code that "does the job". Send log output to STDOUT or STDERR. Don't fork background processes.

The concept of daemontools is often copied, you can find a very similar implementation in runit standalone and in busybox, systemd also expect daemons to run under its control, so does upstart.

All of these systems need extra work for daemons that fork themselves to the "background". Even a classic init that controls a daemon expect it not to fork to "background". The "going to background" is only really meaningful when starting daemons manually from a (virtual) terminal or the console, and there, a small shell script using kill, fork, exec, nohup and i/o redirection makes much more sense. This script can also be used from classic init scripts.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)


Comment on Re: A few questions regarding Proc::Daemon
Re^2: A few questions regarding Proc::Daemon
by walkingthecow (Friar) on Nov 08, 2013 at 10:00 UTC
    I'm trying to write a daemon, not trying to replace systemd, initd, upstart, etc. Your suggestion seems way overkill as an answer to my question.
      I'm trying to write a daemon, not trying to replace systemd, initd, upstart, etc.

      Yes, I know.

      Your suggestion seems way overkill as an answer to my question.

      No. You did not understand my answer. Your daemon is doing too much work. Let the operating system (i.e. daemontools, systemd, init, upstart, ...) handle forking, logging, restarting. Write your daemon so that it does not fork to "background", does not re-invent logging, does not re-invent sending signals to a running process, does not re-invent configuration, etc. Have a look at the daemontools and services sections of the djb way.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Ohhh, stupid me! Sorry, I thought you were saying to replace upstart, init, systemd, etc with daemontools. I get what you're saying now. I just figured that the daemon would need to understand stop, status, etc in order to shutdown gracefully, give a status, and so on. I guess I was wrong in this assumption?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1061682]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2014-07-24 03:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (156 votes), past polls