UNPKG

the-shepherd

Version:

Control a herd of wild processes.

30 lines (28 loc) 935 B
Http = require('http'); Shell = require('shelljs'); Fs = require('fs'); $ = require('bling'); console.log("Test Server starting on PID:", process.pid); ["SIGHUP", "SIGINT", "SIGTERM"].forEach(function(signal) { process.on(signal, function() { console.log("got signal: " + signal); process.exit(0) }) }); $.delay(500, function() { // add an artificial startup delay Http.createServer(function(req, res) { var fail = function(err) { res.statusCode = 500; res.contentType = "text/plain"; res.end(err.stack) console.log(req.method + " " + req.url + " " + res.statusCode) }, finish = function(text) { res.statusCode = 200; res.contentType = "text/plain"; res.end(text || "") console.log(req.method + " " + req.url + " " + res.statusCode) } finish('{"PORT": ' + process.env.PORT + ', "PID": "' + process.pid + '"}') }).listen(process.env.PORT); console.log("Listening on port", process.env.PORT) })