-
-
Save stephenhandley/2640351 to your computer and use it in GitHub Desktop.
djp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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