1

This is a problem I've experienced on Ubuntu 11.04, with the two upstart scripts I've made, for Node and Nginx. I'll use Node here as the example. I'm using a fairly standard setup as on tutorials like http://howtonode.org/deploying-node-upstart-monit:

start on started mountall
stop on shutdown

respawn
respawn limit 5 60

sudo -u username /usr/local/bin/node /path/to/app.js 2>&1 >> /var/log/node.log

Starts fine with "start app". But then I manually killed the node process to force a restart, and unfortunately upstart didn't respawn it. In fact, upstart won't respawn it no matter what I do. It shows the following, all the while not starting Node at all:

> sudo start app
app start/running, process 15211
> sudo stop app
stop: Unknown instance: 
> sudo status app
app stop/waiting
mahemoff
  • 44,526
  • 36
  • 160
  • 222
  • Are you stopping the app and waiting to see if it will start automatically or are you referring to restarting the machine and the app doesn't start? – Chris Abrams Sep 22 '11 at 19:46
  • Stopping it automatically, by killing the process. – mahemoff Sep 26 '11 at 15:21
  • 1
    unless you are using `kill -9`, node will receive a TERM, which will shut it down normally; it only respawns on an abnormal shutdown. – Kato Dec 02 '11 at 10:29

1 Answers1

1

Try changing your sudo part of your code to below. I know you have to include export home although I haven't seen any documentation say why. You are changing where it says "sudo -u username" to the username that will be running this code correct? You are also changing the path to the correct location of app.js on the server correct?

script  
    export HOME="/root"  
    exec sudo -u username /usr/local/bin/node /path/to/app.js 2>&1 >> /var/log/node.log  
end script  

I am not sure if this will help but I've seen some people replace:

start on started mountall  

to

start on (local-filesystems and net-device-up IFACE=eth0)
Chris Abrams
  • 39,732
  • 19
  • 51
  • 57