Skip to content

Instantly share code, notes, and snippets.

@patcoll
Created December 7, 2012 02:26
Show Gist options
  • Save patcoll/4230246 to your computer and use it in GitHub Desktop.
Save patcoll/4230246 to your computer and use it in GitHub Desktop.
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