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?
Edit 1
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.
You really should try to use
screen
. It is a bit more complicated than just doingnohup long_running &
, but understanding screen once you never come back again.Start your screen session at first:
Run anything you want:
Press ctrl+A and then d. Done. Your session keep going on in background.
You can list all sessions by
screen -ls
, and attach to some byscreen -r 20673.pts-0.srv
command, where 0673.pts-0.srv is an entry list.To run command as a system service on debian with sysv init:
Copy skeleton script and adapt it for your needs, probably all you have to do is to set some variables. Your script will inherit fine defaults from
/lib/init/init-d-script
, if something does not fits your needs - override it in your script. If something goes wrong you can see details in source/lib/init/init-d-script
. Mandatory vars areDAEMON
andNAME
. Script will usestart-stop-daemon
to run your command, inSTART_ARGS
you can define additional parameters ofstart-stop-daemon
to use.That is how I run some python stuff for my wikimedia wiki:
Besides setting vars I had to override
do_stop_cmd
because of python substitutes the executable, so service did not stop properly.