I connect to the linux server via putty SSH. I tried to run it as a background process like this:
$ node server.js &
However, after 2.5 hrs the terminal becomes inactive and the process dies. Is there anyway I can keep the process alive even with the terminal disconnected?
Actually, I tried
nohup, but as soon as I close the Putty SSH terminal or unplug my internet, the server process stops right away.
Is there anything I have to do in Putty?
Edit 2 (on Feb, 2012)
There is a
node.js module, forever. It will run node.js server as daemon service.
Simple solution (if you are not interested in coming back to the process, just want it to keep running):
nohup node server.js &
Powerful solution (allows you to reconnect to the process if it is interactive):
You can then detach by pressing Ctrl+a+d and then attach back by running
Also consider the newer alternative to screen, tmux.
nohup node server.js > /dev/null 2>&1 &
nohupmeans: Do not terminate this process even when the stty is cut off.
> /dev/nullmeans: stdout goes to /dev/null (which is a dummy device that does not record any output).
2>&1means: stderr also goes to the stdout (which is already redirected to
/dev/null). You may replace &1 with a file path to keep a log of errors, e.g.:
&at the end means: run this command as a background task.