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
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"):
screen
sessionnohup
disown
s it and closes associated STDOUT and STDERR channels.Try this:
Some other ways:
Here's another way to do it without
nohup
: disown it.E.g.:
Explaination:
jobs
to show background jobs, there are nonesleep 300
jobs
again. PID forsleep
is 79844 and is job #1jobs
again. No background jobs.pgrep
to find any processes namedsleep
. 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 toSTDOUT
.