Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL #74

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

REPL #74

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ exports = module.exports = function(files, options){
* Directories to ignore.
*/

exports.ignoreDirectories = ['node_modules', 'support', 'test', 'bin'];
exports.ignoreDirectories = ['node_modules', 'support', 'test', 'bin'];
28 changes: 20 additions & 8 deletions lib/plugins/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ 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 = [];


// 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
Expand All @@ -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
Expand All @@ -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();
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

var fs = require('fs')
, Log = require('log')
// , Log = require('log')
, repl = require('./repl')
, utils = require('../utils')
, os;
Expand Down