Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

exec command

  • Loading branch information...
commit 765499300c5e3955a3e2086177c2154d98512d20 1 parent 40d0ce0
@substack authored
Showing with 81 additions and 4 deletions.
  1. +73 −0 bin/exec.js
  2. +1 −0  bin/hub.js
  3. +3 −1 bin/monitor.js
  4. +4 −3 package.json
View
73 bin/exec.js
@@ -0,0 +1,73 @@
+#!/usr/bin/env node
+var argv = require('../lib/argv');
+var propagit = require('propagit');
+var git = require('../lib/git');
+
+var EventEmitter = require('events').EventEmitter;
+
+var p = propagit(argv);
+p.on('error', function (err) {
+ console.dir(err);
+});
+
+p.hub(function (hub) {
+ var opts = {
+ drone : argv.drone,
+ drones : argv.drones,
+ repo : argv.repo || git.repoName(),
+ commit : argv.commit,
+ command : argv._,
+ env : argv.env || {},
+ cwd : argv.cwd,
+ once : true
+ };
+ if (!opts.repo) {
+ console.error('specify --repo or navigate to a git repo');
+ return;
+ }
+ if (!opts.commit) git.commit(function (err, commit) {
+ if (err) {
+ console.error(err);
+ p.hub.close();
+ }
+ else {
+ opts.commit = commit;
+ spawn(hub, opts);
+ }
+ })
+ else spawn(hub, opts);
+});
+
+function spawn (hub, opts) {
+ var em = new EventEmitter;
+ hub.subscribe(em.emit.bind(em));
+ em.on('ready', function () {
+ hub.spawn(opts, function (err, procs) {
+ if (err) {
+ console.error(err)
+ p.hub.close();
+ }
+ else {
+ em.on('stdout', function (buf, proc) {
+ if (procs[proc.drone] !== proc.id) return;
+ console.log(
+ '[' + proc.drone + '#' + proc.id + '] '
+ + buf.replace(/\n$/, '')
+ );
+ });
+ em.on('stderr', function (buf, proc) {
+ if (procs[proc.drone] !== proc.id) return;
+ console.log(
+ '[' + proc.drone + '#' + proc.id + '] '
+ + buf.replace(/\n$/, '')
+ );
+ });
+ em.on('exit', function (code, sig, proc) {
+ if (procs[proc.drone] !== proc.id) return;
+ console.log('(' + proc.drone + '#' + proc.id + ' exited)');
+ p.hub.close();
+ });
+ }
+ });
+ });
+}
View
1  bin/hub.js
@@ -22,6 +22,7 @@ prop.use(function (service, conn) {
delete subs[conn.id];
});
subs[conn.id] = emit;
+ emit('ready');
}
};
});
View
4 bin/monitor.js
@@ -15,7 +15,9 @@ p.hub.on('up', function (hub) {
});
em.on('stdout', function (buf, opts) {
- console.dir([ 'stdout', buf, opts ]);
+ if (opts) {
+ console.dir([ 'stdout', buf, opts ]);
+ }
});
hub.subscribe(em.emit.bind(em));
View
7 package.json
@@ -1,7 +1,7 @@
{
"name" : "fleet",
"description" : "command a cluster of processes ",
- "version" : "0.0.1",
+ "version" : "0.0.2",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/fleet.git"
@@ -16,7 +16,8 @@
"fleet-ps" : "bin/ps.js",
"fleet-monitor" : "bin/monitor.js",
"fleet-spawn" : "bin/spawn.js",
- "fleet-stop" : "bin/stop.js"
+ "fleet-stop" : "bin/stop.js",
+ "fleet-exec" : "bin/exec.js"
},
"keywords" : [
"cluster",
@@ -32,7 +33,7 @@
"test" : "tap test/*.js"
},
"dependencies" : {
- "propagit" : "~0.4.10",
+ "propagit" : "~0.5.0",
"optimist" : "~0.3.1",
"mkdirp" : "~0.3.0"
},
Please sign in to comment.
Something went wrong with that request. Please try again.