public
Created

node.js as a system web service with upstart

  • Download Gist
app.conf
1 2 3 4 5 6 7 8 9 10 11
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
app.js
JavaScript
1 2 3 4 5 6 7 8
var express = require('express');
var app = express.createServer();
 
app.get("/", function(req, res, next) {
res.send("Hello World\n");
});
 
exports = module.exports = app;
run.js
JavaScript
1 2 3 4 5 6 7
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');
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.