Care about children of supervised processes #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
daemons that forked their own children always were a big problem for supervision, since when the daemon dies, the orphaned children are out of sight of the supervisor. This was especially a problem for classical Unix daemons that forked immediately. This is what
fghack
is for, but as the name suggests this is only a hack. And it does not address the problem of daemons that completely legally spawn children.This used to be a problem based on the operating system itself, as unices had no method to prevent that, and apparently POSIX was silent on that problem.
Recently, both Linux and FreeBSD (including DragonFly) have introduced a solution to this problem: subprocess reapers. If a process dies, all its children are adopted by the subprocess reaper.
supervise
is the ideal candidate to be such a subprocess reaper.This pull request adds a new flag file
orphanage
to service directories. It means that if the supervised daemon dies,supervise
goes into aorphanage
state, meaning it waits until all children have died (I am not aware of a simple way to kill all orphans). Only once that's done, the service is restarted (if so demanded).This works well in combination with
supervise
creating a new process group, this way it is possible to send a signal to all children to terminate them.I consider the new subprocess reaper functionality in Linux and FreeBSD a huge step forward in the field of process supervision, that it should be added to
daemontools-encore
, even if it cannot be supported on all platforms. On non-supported platforms, everything stays as-is, as theorphanage
options is just an add-on.