Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

REPL #74

Open
wants to merge 6 commits into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 1, 2011
  1. @dvv

    coffee support

    dvv authored
  2. @dvv
Commits on Mar 2, 2011
  1. @dvv
Commits on Apr 5, 2011
  1. @dvv

    Merge branch 'master' of github.com:LearnBoost/cluster

    dvv authored
    Conflicts:
    	lib/plugins/repl.js
    	lib/worker.js
  2. @dvv

    Merge branch 'master' of github.com:LearnBoost/cluster

    dvv authored
    Conflicts:
    	lib/plugins/reload.js
  3. @dvv

    REPL for console

    dvv authored
This page is out of date. Refresh to see the latest.
View
10 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');
+ }
};
/**
View
2  lib/plugins/reload.js
@@ -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'];
View
28 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();
});
}
};
View
2  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;
Something went wrong with that request. Please try again.