Add daemonization for node - #39
Merged
Merged
Conversation
rustaceanrob
force-pushed
the
26-3-9-daemonize
branch
3 times, most recently
from
March 10, 2026 11:13
5b2974e to
0709d57
Compare
`libc` is brought in here to do a couple of calls. First, a `fork` is used to create a child process. Then, if the process is the parent, the program exits immediately. If the process is the child, a new session is made where the child is the group leader, and gives that session an ID. Following the creation of a new session, the environment is moved to the working directory, were the `stdout`, `stderr`, and `pid` file are written. All `stdin` are dropped by writting to `/dev/null`. The `umask` set allows for the process owner to read/write, and the group to read. This was otherwise straightforward, however the logging appears to go to `stderr` instead of `stdout` for some reason. I am unsure if this is a quark of the logging library or a personal misunderstanding. In any case, both `stdout` and `stderr` are written to the same file. ref: https://man7.org/linux/man-pages/man2/fork.2.html ref: https://man7.org/linux/man-pages/man2/setsid.2.html ref: https://unix.stackexchange.com/questions/286373/does-the-ubuntu-linux-16-04-daemon-function-execute-a-double-fork ref: https://thelinuxcode.com/umask-in-linux-default-permissions-bitwise-math-and-real-examples-you-can-trust/
rustaceanrob
force-pushed
the
26-3-9-daemonize
branch
from
March 11, 2026 15:47
0709d57 to
bb59ecd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #25
From commit one, references in commit:
libcis brought in here to do a couple of calls. First, aforkis used to create a child process. Then, if the process is the parent, the program exits immediately. If the process is the child, a new session is made where the child is the group leader, and gives that session an ID. Following the creation of a new session, the environment is moved to the working directory, where thestdout,stderr, andpidfile are written. Allstdinare dropped by writting to/dev/null. Theumaskset allows for the process owner to read/write, and the group to read.This was otherwise straightforward, however the logging appears to go to
stderrinstead ofstdoutfor some reason. I am unsure if this is a quark of the logging library or a personal misunderstanding. In any case, bothstdoutandstderrare written to the same file.Tested this with both killing from the
pidfile and graceful shutdown.