Create a gist now

Instantly share code, notes, and snippets.

node.js as a system web service with upstart
description "app"
start on filesystem
stop on runlevel S
respawn
env PORT=3002
env APP_USER=app
# @TODO: put NODE_ENV here
env NODE_PATH=/usr/local/lib/node_modules
exec /usr/local/bin/node /var/www/run.js >> /var/log/app.log 2>&1
var express = require('express');
var app = express.createServer();
app.get("/", function(req, res, next) {
res.send("Hello World\n");
});
exports = module.exports = app;
var app = require('./app');
app.listen(process.env.PORT || 3000, function() {
if (process.getuid() === 0) {
process.setgid(process.env.APP_USER || 'www-data');
process.setuid(process.env.APP_GROUP || process.env.APP_USER || 'www-data');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment