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)