3

I'm trying to keep an application on my ubuntu server running so that Google has time ping it, but the app keeps shutting down when I log out.

I start the Nodejs app with supervisor to monitor changes (via a shell script)

I found commands like nohup, but I'm really clueless when it comes to running background services other than typing simple commands like service httpd start which seems to work pretty well for Apache on CentOS!

Do I need to create another user to run services on? I have a Linode instance with Ubuntu 10.04

run.sh

cd myapp/src/main/node
supervisor -w "myapp/src/main/node,myapp2/src/main/node,./" run-apps.js
5

Try this:

nohup supervisor -w "myapp/src/main/node,myapp2/src/main/node,./" run-apps.js &

Some other ways:

5

The reason it exits is because when you logout and terminate the parent shell, the script receives a HUP signal and loses its ability to write to STDOUT and STDERR.

You have 4 options, (in order of "correctness" and "cleanness"):

  1. Modify it so that it ignores a HUP signal and logs cleanly to a file.
  2. Run the script in a screen session
  3. Run the script using nohup
  4. Create a fairly complex bash script that launches the script then disowns it and closes associated STDOUT and STDERR channels.
  • Thank you for this! How would I use any of these commands say nohup or screen with supervisor as part of my shell script? – qodeninja Sep 21 '12 at 16:26
1

Here's another way to do it without nohup: disown it.

E.g.:

$ jobs
$ sleep 300 &
[1] 79844
$ jobs
[1]  + running    sleep 300
$ disown %1
$ jobs
$ pgrep sleep
79844

Explaination:

  1. Use jobs to show background jobs, there are none
  2. Background sleep 300
  3. Use jobs again. PID for sleep is 79844 and is job #1
  4. Disown job #1
  5. Use jobs again. No background jobs.
  6. Use pgrep to find any processes named sleep. There is one, with PID 79844 (same PID)

You can close the terminal and/or logout without affecting the disowned job.

This has the advantage of not leaving around a nohup.out file, but you also lose anything written to STDOUT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.