Skip to content

Instantly share code, notes, and snippets.

@stephenhandley
Created May 8, 2012 23:24
Show Gist options
  • Save stephenhandley/2640351 to your computer and use it in GitHub Desktop.
Save stephenhandley/2640351 to your computer and use it in GitHub Desktop.
djp
#!/bin/env node
// OpenShift sample Node application
// Get the environment variables we need.
var ipaddr = process.env.OPENSHIFT_INTERNAL_IP;
var port = process.env.OPENSHIFT_INTERNAL_PORT || 8080;
if (typeof ipaddr === "undefined") {
console.warn('No OPENSHIFT_INTERNAL_IP environment variable');
}
// terminator === the termination handler.
function terminator(sig) {
if (typeof sig === "string") {
console.log('%s: Received %s - terminating Node server ...',
Date(Date.now()), sig);
process.exit(1);
}
console.log('%s: Node server stopped.', Date(Date.now()) );
}
// Process on exit and signals.
process.on('exit', function() { terminator(); });
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS',
'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGPIPE', 'SIGTERM'
].forEach(function(element, index, array) {
process.on(element, function() { terminator(element); });
});
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('D J P\n');
}).listen(port, ipaddr);
console.log(
'%s: Node server started on %s:%d ...',
Date(Date.now()),
ipaddr,
port
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment