So I wrote a seemingly-basic node.js server upstart script based on a script from this article, and it works fine, starting the server and running on the expected port. The problem comes when I try to kill it.

I've tried a few commands, like stop socketserver and initctl stop socketserver (functionally equivalent) or kill and they all do two things: successfully end the process, then start it right back up under a different pid.

All I want is for this process to end when I tell it to, but respawn when it's not a valid exit code; what've I done wrong?

description "node.js Socket Server"
author      "moberemk"

start on started
stop on shutdown

# Automatically Respawn
respawn limit 10 5

    # Not sure why $HOME is needed, but we found that it is:
    export HOME="/root"
    export SOCKETSERVER_PORT=5000

    exec sudo -u root /usr/bin/nodejs /vagrant/webroot/socketserver/app.js
end script

(also I know the script might kind of give this away, but I'm running this on a Vagrant box using Ubuntu 14.04)


it appears as though you're instructing upstart to do something rather extraordinary:

start on started

this line doesn't trigger a syntax error. but generally you would specify a start stanza like so:

start on started some-other-service

assuming you want your nodejs service to run at startup (and assuming it requires an internet connection) perhaps you meant to do something like:

start on (local-filesystems and net-device-up IFACE!=lo)


start on started

after investigating further, i've determined that this stanza actually causes upstart to run your service whenever another service has finished starting which would explain why your process has been rendered unkillable.

|improve this answer|||||
  • Your suggested line is actually identical to what we ended up going with on our live production server, so I'm going to mark this as accepted. That's good to know about the started event, I'm a little surprised that event exists but I suppose it would have its uses. – moberemk Aug 17 '15 at 17:22

Comment out or delete the respawn lines

|improve this answer|||||
  • Sure that works, but generally I WANT that respawn behavior, except when I want to manually kill the process. Shouldn't respawn respect a manual stop, or at least have the option to support that? – moberemk Jul 23 '15 at 20:31
  • What about service yourservice stop? – Uwe Burger Jul 23 '15 at 20:35
  • Triggers a respawn; the console just tells me the pid of the newly-started process. – moberemk Jul 23 '15 at 20:38
  • Sorry i am not using upstart any more, have switched to systemd. Maybe ask in ubuntu forum? – Uwe Burger Jul 23 '15 at 20:51

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.