Autor: Isaac Dunham Data: Para: poitr pogo CC: dng Assunto: Re: [Dng] Why daemontools is so cool
On Sat, Mar 28, 2015 at 02:52:47PM +0100, poitr pogo wrote:
(in response to the question of why s6 "prevents daemonizing") > Cannot. This is from the s6 docs. I'm not using s6. Just heard about it today.
If you want to *manage* a daemon (ie, do something when it stops, like
restarting it), it's very tricky to do it reliably without having a fixed
PID; "daemonizing" means close stdin/stdout/stderr, then
if (fork()) exit(0);
or some such thing (in other words, create a new process and exit the
old one), so you do not have a fixed PID.
On Linux, BSD, and older UNIX versions, this can be done thus:
daemon(0,0);
> Another s6 limitation - finish script must end in 3 seconds. or will be killed.
> Nice for desktop, not a server.
sysvinit /etc/init.d/sendsigs actually only allows 1 second.
> It used to be that an application is responsible for proper start
> up/shutdown procedure, as application knows the proper way how to do
> it. Init script is just a place where to hook a startup/shutdown
> script to be executed when system needs to start/stop application in
> some automatic way. > Now there are tools which help deamonize things.
> Depending how portable they are it make the price one has to pay when
> decides to use them instead of handling this yourself in the
> application.
My understanding is that s6 and some of the equivalent packages, such
as daemontools, are fairly portable.
They are generally not used as a way to offload daemonizing, but as a
way to ensure that a service stays started. If you don't need that,
you don't need them.
> Regards
> piotr