I'm trying to start nodejs server in background:
nodejs my_app.js &
But it shows the debug messages ("Starting at 0.0.0.0 ...") and then I disconnect from my server via ssh, it terminates. Why?
I'm trying to start nodejs server in background:
nodejs my_app.js &
But it shows the debug messages ("Starting at 0.0.0.0 ...") and then I disconnect from my server via ssh, it terminates. Why?
Because with '&' your node process is still tied to the calling process (e.g. the Shell you typed this in). By killing your ssh-session you also kill all of its child processes.
The answer from @SourbhGupta is the one go with. nohup
lets the child process ignore the hang up Signal. So, killing the calling process has no effect on its child process.
Run it inside screen.
Screen process runs on background.
1.sudo apt-get install screen
2.screen (To start a screen process)
3.Run your service
4.node my_app.js (without & will do)
5.Ctrl+a+k to detach it.
For more information on screen- https://www.digitalocean.com/community/tutorials/how-to-install-and-use-screen-on-an-ubuntu-cloud-server