I have a webserver written in node.js and I have a bash script that starts it:
nohup `node ~/path/to/app.js -ms` > /dev/null 2>&1 &
stderr is redirected to stdout and both are redirected to /dev/null, I don't want any output file.
The process is executed in background and is executed with nohup.
The problem is that I access to the server via ssh. If I logout the process is still executing but a few hours later the process dies. What I'm doing wrong?
EDIT:
Forget nohup and &. Specific node.js solution:
boot.js
require ("child_process").spawn ("node", process.argv.slice (2), {
stdio: "inherit", detached: true
}).unref ();
Usage:
node boot app.js <params>
Remove the backticks and redirect at least STDERR to a log file:
nohup node ~/path/to/app.js -ms >/dev/null 2>/var/log/app_error.log &
You won't be able to debug this without getting at least some information about what's going on.
Ansgar Wiechers gave you a good suggestion about nohup.
Given that there are better ways to manage your node.js processes than nohup.