Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Running multiple instances of a daemon simultaneously?

by afoken (Chancellor)
on Aug 10, 2014 at 08:46 UTC ( [id://1096899]=note: print w/replies, xml ) Need Help??


in reply to Running multiple instances of a daemon simultaneously?

When it comes to writing daemons, I prefer not to have to think about daemons at all. I write a program that runs "in foreground" (whatever that means), it does not fork to "run in background", it logs by simply writing to STDERR, and it does not maintain a PID file. That reduces the amount of code needed.

How do I get my programs to run as daemons "in background"? Easy, I use djb's daemontools, or one of the various toolsets using the same concept, e.g. runsv from busybox.

Daemontools handle all of the daemonizing, i.e. running "in background", switching user IDs, configuration, reliable logging even across program restarts and crashes, starting and stopping, sending signals to the daemon, and so on. See also Re^3: Proc::PID::File problem generating pid files, or: does it matter where a pid file lives?, Re^3: How to capture system return code when command launched in the background?, Re: Executing script in normal/daemon mode and adding start/stop capability, Re^5: A few questions regarding Proc::Daemon, daemontools at "the djb way".

And by the way: you simply do not need any PID file with daemontools. Of course, you can run multiple instances of the same program with different options via daemontools.

Note that you also do not need any daemonizing code in your program when you use daemontools, not even Proc::Daemon. In fact, such code makes it harder to use daemontools.

So, how hard is it to write a daemon using daemontools? Less than 10 lines of simple shell code, including configuration and logging.

Alexander

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

Replies are listed 'Best First'.
Re^2: Running multiple instances of a daemon simultaneously?
by Trenin (Initiate) on Aug 12, 2014 at 13:39 UTC
    Awesome, thanks for all of the links and information.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-04-24 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found