Skip to content

Commit

Permalink
Disable interactive mode if stdin is not available
Browse files Browse the repository at this point in the history
Previously an exception would be thrown if stdin was not available at
startup. This change allows tick-cluster to continue albeit with
interactive commands disabled.

This change allows tick-cluster to be spawned in the background for
tests.
  • Loading branch information
dansimau committed Nov 27, 2015
1 parent b91a2db commit 059037e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions scripts/tick-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function startCluster() {
}

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'));
logMsg('init', color.cyan('tick-cluster started '));

findLocalIP();
hosts = generateHosts(localIP, 3000, procsToStart, 'hosts.json');
Expand All @@ -491,11 +491,16 @@ function main() {
trace: false
});

var stdin = process.stdin;
stdin.setRawMode(true);
stdin.resume();
stdin.setEncoding('utf8');
stdin.on('data', onData);
try {
var stdin = process.stdin;
stdin.setRawMode(true);
stdin.resume();
stdin.setEncoding('utf8');
stdin.on('data', onData);
logMsg('init', 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'));
} catch (e) {
logMsg('init', 'Unable to open stdin; interactive commands disabled');
}
}

function displayMenu(logFn) {
Expand Down

0 comments on commit 059037e

Please sign in to comment.