Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Looking for a daemonizing module

by 1nickt (Abbot)
on Sep 09, 2019 at 06:42 UTC ( #11105853=note: print w/replies, xml ) Need Help??


in reply to Looking for a daemonizing module

Hi, I would not advise daemonizing your program inside itself, nor to use Perl for it. I suggest writing your program and making it capable of running in single-process mode or with multiple workers (using MCE you can achieve single-process mode via the number of workers flag), and then separately installing and configuring it as a service (daemon) on the machines where it will run. The OS and standard utilities are much better designed to handle this and all related tasks, such as log rotation, startup at boot time, etc.

FWIW I recommend daemontools for Unices.

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Looking for a daemonizing module
by afoken (Canon) on Sep 09, 2019 at 19:09 UTC
    I recommend daemontools for Unices.

    I can only second that. Writing daemons to be compatible with daemontools (i.e. forget about almost all aspects of running as a daemon) automatically makes them compatible with tons of other tools that copied the daemontools idea (almost all alternatives to a classic init, xinetd, and even the nightmare systemd).

    See also:


    Just another little note: If you write your daemon to be compatible with daemontools, it can be incredible compact. A hello world deamon can be written as a bourne shell script in less than 10 lines of code:

    #!/bin/sh # blabbyd.sh: a blabby daemon, version 2 # # note: variables now provided from environment with envdir: # # .env/MESSAGE # .env/PAUSE # echo "starting blabbyd..." # loop forever while : do echo "blabbyd: ${MESSAGE}" echo "blabbyd: sleeping for ${PAUSE} seconds..." sleep ${PAUSE} done # that's all, folks!

    (Copied right out of the djb way)

    All that you think is missing for a daemon is already implemented by daemontools or some other, compatible software. You don't have to reinvent the wheel.

    Alexander

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2019-10-24 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?