Created
July 17, 2012 04:36
-
-
Save tblobaum/3127178 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
// a list of meta data for all services | |
// probably loaded from a json file or database | |
var settings = { | |
api : { name : 'api' } | |
, static : { name : 'static' } | |
} | |
var Seaport = require('seaport') | |
, seaport = seaport.connect({ host : '0.0.0.0', port : 1026 }) | |
, spawn = require('child_process').spawn | |
, args = process.argv.splice(2) | |
, processes = [] | |
// example: | |
// - ./bin/seawrap api static | |
// - ./bin/seawrap api | |
args.forEach(function (name) { | |
seaport.service(settings[name], function (port) { | |
var ps = spawn('node', [ __dirname + '/../' + name, port ], { cwd: process.cwd() }) | |
ps.stdout.pipe(process.stdout) | |
ps.stderr.pipe(process.stderr) | |
console.info(name, port) | |
ps.on('exit', function (code, signal) { | |
console.error(name, 'died', code, signal) | |
processes.forEach(function (p) { p.exit(code) }) | |
}) | |
processes.push(ps) | |
}) | |
}) |
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
var port = process.argv[2] || 3000 | |
http.createServer(function () { /* */ }).listen(port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment