Search code examples
ubuntuconfigupstart

Ubuntu upstart won't respawn


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

Solution

  • 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)