diff --git a/lib/master.js b/lib/master.js index c8a7997..d88c1a1 100644 --- a/lib/master.js +++ b/lib/master.js @@ -97,6 +97,7 @@ var Master = module.exports = function Master(server) { // grab server root this.cmd = process.argv.slice(1); + if (this.cmd[0].slice(-7) === '.coffee') node = 'coffee' this.dir = dirname(this.cmd[0]); // defaults @@ -474,7 +475,14 @@ Master.prototype.removeWorker = function(id){ */ Master.prototype.spawn = function(n){ - while (n--) this.spawnWorker(); + // add fresh workers + if (n > 0) { + while (n--) this.spawnWorker(); + // remove excess workers + } else if (n < 0) { + this.options.workers = Math.max(this.options.workers + n, 0); + this.kill();//'SIGQUIT'); + } }; /** diff --git a/lib/plugins/reload.js b/lib/plugins/reload.js index f1457ce..d0b8bf0 100644 --- a/lib/plugins/reload.js +++ b/lib/plugins/reload.js @@ -122,4 +122,4 @@ exports = module.exports = function(files, options){ * Directories to ignore. */ -exports.ignoreDirectories = ['node_modules', 'support', 'test', 'bin']; \ No newline at end of file +exports.ignoreDirectories = ['node_modules', 'support', 'test', 'bin']; diff --git a/lib/plugins/repl.js b/lib/plugins/repl.js index 7c410eb..b25573a 100644 --- a/lib/plugins/repl.js +++ b/lib/plugins/repl.js @@ -32,7 +32,7 @@ var net = require('net') exports = module.exports = function(){ var args = arguments; - if (!args.length) throw new Error('repl() plugin requires port/host or path'); + //if (!args.length) throw new Error('repl() plugin requires port/host or path'); return function(master){ var server , sockets = []; @@ -40,10 +40,13 @@ exports = module.exports = function(){ // start repl function start(){ - // TCP or unix-domain socket repl - server = net.createServer(function(sock){ - sockets.push(sock); + + function REPL(sock) { var ctx = repl.start('cluster> ', sock).context; + // console.repl? + if (!sock) { sock = process.stdout; } + + sockets.push(sock); master.emit('repl socket', sock); // augment socket to provide some formatting methods @@ -59,10 +62,19 @@ exports = module.exports = function(){ return exports[cmd].apply(master, args); }; }); - }); + } + + // console repl + if (!args.length) { + process.stdin.on('close', process.exit); + REPL(); + // TCP or unix-domain socket repl + } else { + server = net.createServer(REPL); + // Apply all arguments given + server.listen.apply(server, args); + } - // Apply all arguments given - server.listen.apply(server, args); } // initial master starts immediately @@ -86,7 +98,7 @@ exports = module.exports = function(){ sockets.forEach(function(sock){ sock.fd && sock.end(); }); - if (server.fd) server.close(); + if (server && server.fd) server.close(); }); } }; diff --git a/lib/plugins/stats.js b/lib/plugins/stats.js index 052033f..6dc55fc 100644 --- a/lib/plugins/stats.js +++ b/lib/plugins/stats.js @@ -10,7 +10,7 @@ */ var fs = require('fs') - , Log = require('log') +// , Log = require('log') , repl = require('./repl') , utils = require('../utils') , os;