by topspin · 2y ago · 0 comments
By whom and for what reason? Every non-trivial OS has some form of "daemon" concept, regardless of what name it's given. What alternative is proposed? All I get from this statement is discussion about the deficiencies of how demonization is performed.
[edit] I get it. Don't deamonize yourself. That's fine, and a good idea: it's frequently done wrong and even when it's done right things change and otherwise correct software is suddenly wrong again.
From OpenRC’s docs[0]:
Daemons must not fork. Any daemon that you would like to have monitored by supervise-daemon must not fork. Instead, it must stay in the foreground. If the daemon forks, the supervisor will be unable to monitor it.
If the daemon can be configured to not fork, this should be done in the daemon's configuration file, or by adding a command line option that instructs it not to fork to the command_args_foreground variable shown below.
The “undesired” or “controversial” part is whether programs should do it themselves or not.[0]: https://github.com/OpenRC/openrc/blob/master/supervise-daemo...
It made a lot of sense to me at the time and honestly felt easier. Going back to init.d or upstart just felt like a step backward and so much more complicated that it needed to be. Then SystemdD comes along an have the same expectation and things makes sense again and writing "startup scripts became as easy almost as it was with daemontools.
I’d say it’s the modern-day equivalent of daemontools, and it’s under active development.
One, is that HTTP took over the role of a lot of simple servers, thus something like Apache and CGI-BIN was used in place of inetd.
Second, with the rise of interpreted languages (i.e. Perl et al), forking became more expensive. With binary programs, forking tends to be cheap (in a multi-use case) since the executable page are shared across processes. While the interpreter runtime itself is shared (being compiled), the actual script is not (having to be loaded for each instance).
The HTTP servers managed that better (through modules, FastCGI, etc.), so that space didn't really advance under the guise of inetd.
Make no mistake, an inetd service is "fast enough" for a wide array of use cases today, both compiled and interpreted, simply because the hardware is much better today. But, still, when folks think "ad hoc" service today, they're likely turning to HTTP today anyway.
I don’t recall whether you could tell inetd not to do that.
By everyone and for the reason that service managers lose track of the process, so it increases program complexity for a net negative in usability.
> Every non-trivial OS has some form of "daemon" concept, regardless of what name it's given.
And none of that is relevant, TFA is about the unix self-daemonization pattern, that is what's undesirable.
"Daemonization" is nothing but fork + exec (and exit from the parent)
From the service manager, there should be few distinctions between this and, say, pgsql forking to handle connections. In both cases, I expect all child processes to be tracked.
And please do not tell me the "health check" part : having the main process alive is a broken health check, just like having a server powered-on is a far from enough
The program that the service manager thinks is starting immediately quits, and it's the grandchild (or even great grandchild) that's actually the payload service.
Because the parent quit, the grandchild becomes reparented to the init daemon; it is not a child of the service manager.
The service manager has no idea what the process ID of the service is.
If the self-daemonizing program writes its PID to a pidfile, and the service manaager is configured to know what that is and look for it, it can be obtained that way.
Not being the parent of the process, the service manager doesn't get notified when that process terminates. It has to use hacks to poll for it; like kill the PID with signal 0 to check liveness, and pray that the PID isn't recycled.
If you're writing a deamon program, make sure daemonization is optional, favoring opt-in over opt-out.
Either you use cgroup (in which case, neither the parent pid nor pidfile nor even the process ID are useful), either you do not (in which case, you leak processes)
Stopping a service means, in the end, killing all processes in the associated cgroup.
If pgsql forks to handle connections, the PPID of the child processes points back to the "main" pgsql process, which is still around.
Whereas, traditionally, if a wannabe daemon forks and exits, the PPID of its now orphaned child reverts to 1.
This sort of behavior makes writing proper systemd unit files and containers a pain. It is a lot nicer to keep them 'attached' so that you can do things like capture stdout for logging and all that fun stuff.
That is what they are talking about when "daemonizing is considered undesirable".