1

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
respawn limit 10 5

script
    # 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)

moberemk
  • 113
  • 3

2 Answers2

1

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)

edit

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.

ant
  • 126
  • 5
  • 1
    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
0

Comment out or delete the respawn lines

Uwe Burger
  • 166
  • 3