Search code examples
node.jsubuntusshpackages.config

How can I use ubuntu service to make a process persistent?


I am not convinced that is the right terminology but here is my situation.

I log into an Ubuntu server using ssh and start a node app that I wrote. I would like for the app to continue rinning even when I close the ssh window or when the window times out. I 'think' there is a way to do this by writing a .conf file for the app and placing it in /etc but I dont know where to go to learn how to do that.

Any tips?


Solution

  • You can use the program nohup to accomplish this. It is most likely already installed on your Ubuntu distribution, it was on my 12.04 install.

    nohup node test.js &
    

    This command kicks off node test.js. Output will be streamed to nohup.out so you can view what is has been doing later on if you so like. Even after the ssh session is ended, the process will keep right on going.

    To kill the process later on, you can do a "killall node" or you can manually grep for the PID and kill it that way using "ps -ef | grep node"

    Linux: Prevent a background process from being stopped after closing SSH client