4

Somehow this isn't yielded by a google search.

I'm scripting a server in node.js. I start the server by executing its script with the node program:

node myserver.js

But the server staying up is dependent on my ssh session. How can I make this (and all such processes) persistent? Init.d?

mkrecny
  • 493
  • 4
  • 11

5 Answers5

10

Use the nohup command:

From http://en.wikipedia.org/wiki/Nohup

nohup is a POSIX command to ignore the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out. The HUP (hangup) signal is by convention the way a terminal warns depending processes of logout.

Try this:

nohup node myserver.js &
B Johnson
  • 2,408
  • 3
  • 20
  • 32
  • Is the ampersand intentional there? – mkrecny Nov 01 '10 at 17:51
  • @user470520, yes it is intentional as this indicates to the shell to run this command in the background. If you want to know more about it then read more about Job Control: http://www.gnu.org/software/bash/manual/bashref.html#Job-Control – B Johnson Nov 01 '10 at 18:20
3

Have you tried GNU screen? Using it, a process can continue to run when you end your ssh session. nohup is a standard *nix command that will allow you to do the same, albeit in a more limited way.

darioo
  • 46,442
  • 10
  • 75
  • 103
1

Use screen. Type screen from the terminal and then launch your process. If you disconnect you can reconnect to the ssh session, by typing 'screen -ls' (to see active screens) and 'screen -r' to reconnect.

dr jimbob
  • 17,259
  • 7
  • 59
  • 81
0

The program needs to run in a daemonized mode. Here's a good post for doing this in Ubuntu.

Andrew Sledge
  • 10,163
  • 2
  • 29
  • 30
0

nohup is good to run the job under. If the job is already running, you can try disown -h (at least in bash)

frankc
  • 11,290
  • 4
  • 32
  • 49