NodeBB / NodeBB

Node.js based forum software built for the modern web
https://nodebb.org
GNU General Public License v3.0
14.23k stars 2.8k forks source link

NodeBB's in-process process management does not work with `runit` #4667

Closed jsumners closed 8 years ago

jsumners commented 8 years ago

Void Linux uses runit as its init system. This init system is perfect for running node.js based web services. However, NodeBB does not work well with it.

Using the documentation for Upstart I created my runit service to start NodeBB with:

exec node loader.js --no-silent --no-daemon

This nets me the process tree:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
nodebb   24440  0.1  0.7  41360  5944 pts/0    S    14:36   0:00 -zsh
nodebb   25405  0.0  0.3  12964  2320 pts/0    R+   14:42   0:00  \_ ps ufx
nodebb   11367  0.0  0.0   4220   720 ?        S    Mar13   0:30 runsvdir /home/nodebb/services
nodebb   25386  0.0  0.0   4068   700 ?        S    14:42   0:00  \_ runsv nodebb
nodebb   25387  0.0  0.0   4212   756 ?        S    14:42   0:00      \_ svlogd -t -tt /home/nodebb/logs/nodebb
nodebb   25388  0.0  0.3  14036  2556 ?        S    14:42   0:00      \_ /bin/bash ./run
nodebb   25389 37.0  5.5 945576 42072 ?        Sl   14:42   0:00          \_ node loader.js --no-silent --no-daemon
nodebb   25398 10.0  3.3 904064 25676 ?        Rl   14:42   0:00              \_ /home/nodebb/n/bin/node app.js

That is correct and as it should be. After clicking "reload" and "restart" in NodeBB's admin panel the process tree remains the same; that's perfect.

The issue is when using runit to manage the process. Issuing a sv stop ~/services/nodebb results in the process tree:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
nodebb   24440  0.1  0.7  41360  5952 pts/0    S    14:36   0:00 -zsh
nodebb   25583  0.0  0.2  12964  2256 pts/0    R+   14:46   0:00  \_ ps ufx
nodebb   11367  0.0  0.0   4220   720 ?        S    Mar13   0:30 runsvdir /home/nodebb/services
nodebb   25386  0.0  0.0   4068   700 ?        S    14:42   0:00  \_ runsv nodebb
nodebb   25387  0.0  0.0   4212   756 ?        S    14:42   0:00      \_ svlogd -t -tt /home/nodebb/logs/nodebb
nodebb   25389  0.2  5.5 953420 42496 ?        Sl   14:42   0:00 node loader.js --no-silent --no-daemon
nodebb   25494  4.4 27.1 1349632 206876 ?      Sl   14:44   0:05  \_ /home/nodebb/n/bin/node app.js

Notice that the node process is no longer a child of runsv -- the process manager for runit. This means runit cannot manage the process. Indeed, it was unable to TERM the process to begin with. Process number 25389 should have received the TERM signal and quit when I issued the sv stop command.

julianlam commented 8 years ago

How does runit send the kill signal? Is sv stop supposed to stop NodeBB altogether?

jsumners commented 8 years ago

@julianlam from the manpage:

If the service is running, send it the TERM signal, and the CONT signal. If ./run exits, start ./finish if it exists. After it stops, do not restart service.

So, yes, sv stop is supposed to completely terminate the NodeBB process altogether.

jsumners commented 8 years ago

Oops, somehow exec got missing from my init script. Nothing to see here. Move along.