0

I've got a super simple test node server

# server.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8080/');

I've got a simple upstart script, /etc/init/myapp.conf

description "myapp"
author "me"

start on started
stop on shutdown

exec /usr/bin/node /path/to/server.js

starting works great

sudo start myapp
myapp start/running, process 2518

But stopping just respawns the app

sudo stop myapp
myapp start/running, process 2527

What am I not getting?

PS: I'm using ubuntu 14.04

gman
  • 147
  • 1
  • 6
  • Not sure what's happening in your case. But in mine it was usually due to some forking. That doesn't appear to be your issue though. This might be helpful. At least put the log outputs and start/stop lines. http://howtonode.org/deploying-node-upstart-monit – hookenz Jul 23 '14 at 00:22
  • And this is also very useful http://askubuntu.com/questions/36200/how-to-debug-upstart-scripts – hookenz Jul 23 '14 at 00:23

1 Answers1

1

One problem I see with your Upstart job is the start on stanza. The event that your job starts on is the started event. By reading the man page for upstart-events, one discovers that the started event is emitted when any job is started by Upstart. This is not what you want. Instead, use an event such as runlevel [2345], so that your application is started on all multi user runlevels. This should clear up your problem.

CameronNemo
  • 399
  • 1
  • 6