Skip to content

Commit

Permalink
Add options for interface/port in tick-cluster
Browse files Browse the repository at this point in the history
Adds the --interface option for specifying an interface that
ringpop instances should bind to.

Adds the --port option for specifying the base port that ringpop
instances will use.
  • Loading branch information
dansimau committed Nov 26, 2015
1 parent 1492cc2 commit a085532
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions scripts/tick-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var program = require('commander');
var TChannel = require('tchannel');
var fs = require('fs');

var programInterpreter, programPath, procsToStart = 5;
var programInterpreter, programPath, startingPort, bindInterface, procsToStart = 5;
var hosts, procs, ringPool, localIP, toSuspend, toKill, tchannel; // defined later

/* jshint maxparams: 6 */
Expand Down Expand Up @@ -470,22 +470,25 @@ function killAllProcs() {
}

function startCluster() {
var port = 3000;
procs = []; // note module scope
for (var i = 0; i < procsToStart ; i++) {
procs[i] = new ClusterProc(port + i);
procs[i] = new ClusterProc(startingPort + i);
}
logMsg('init', color.cyan('started ' + procsToStart + ' procs: ') + color.green(procs.map(function (p) { return p.proc.pid; }).join(', ')));
}

function main() {
logMsg('init', color.cyan('tick-cluster started ') + color.red('d: debug flags, g: gossip, j: join, k: kill, K: revive all, l: sleep, p: protocol stats, q: quit, s: cluster stats, t: tick'));

findLocalIP();
hosts = generateHosts(localIP, 3000, procsToStart, 'hosts.json');
if (bindInterface) {
localIP = bindInterface;
} else {
findLocalIP();
}
hosts = generateHosts(localIP, startingPort, procsToStart, 'hosts.json');
startCluster();

tchannel = new TChannel({host: "127.0.0.1", port: 2999});
tchannel = new TChannel({host: "127.0.0.1", port: startingPort + procsToStart + 1});
ringPool = tchannel.makeSubChannel({
serviceName: 'tick-cluster',
trace: false
Expand Down Expand Up @@ -554,6 +557,8 @@ program
.version(require('../package.json').version)
.option('-n <size>', 'Size of cluster. Default is ' + procsToStart + '.')
.option('-i, --interpreter <interpreter>', 'Interpreter that runs program.')
.option('--interface <address>', 'Interface to bind ringpop instances to.')
.option('--port <num>', 'Starting port for instances.')
.arguments('<program>')
.description('tick-cluster is a tool that launches a ringpop cluster of arbitrary size')
.action(function onAction(path, options) {
Expand All @@ -566,6 +571,8 @@ program
procsToStart = parseInt(options.N);
}
programInterpreter = options.interpreter;
bindInterface = options.interface;
startingPort = parseInt(options.port);
});

program.on('--help', function onHelp() {
Expand All @@ -591,4 +598,8 @@ if (isNaN(procsToStart)) {
process.exit(1);
}

if (isNaN(startingPort)) {
startingPort = 3000;
}

main();

0 comments on commit a085532

Please sign in to comment.