Skip to content
Open
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
4 changes: 0 additions & 4 deletions .jscsrc

This file was deleted.

7 changes: 0 additions & 7 deletions .jshintrc

This file was deleted.

9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

8 changes: 0 additions & 8 deletions CHANGELOG.md

This file was deleted.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Proboscis
==============
[![Build Status](https://travis-ci.org/ProboCI/proboscis.svg?branch=master)](https://travis-ci.org/ProboCI/proboscis)
[![Coverage Status](https://coveralls.io/repos/ProboCI/proboscis/badge.png?branch=master)](https://coveralls.io/r/ProboCI/proboscis?branch=master)

This module wraps child processes and unifies their stdout and stderr streams into a signle unified json event stream. It can currnently be used as a library or from the command line.

Expand Down
45 changes: 21 additions & 24 deletions bin/proboscis
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#! /usr/bin/env node
var parse = require('shell-quote').parse;
var es = require('event-stream');
var async = require('async');
var fs = require('fs');
var util = require('util');
var path = require('path');
var Loader = require('yaml-config-loader');
'use strict';

var yargs = require('yargs');
var Proboscis = require('../index');
var server = require('../lib/server');
var runner = new Proboscis();
var loader = new Loader();
const os = require('os');
const parse = require('shell-quote').parse;
const es = require('event-stream');
const Loader = require('yaml-config-loader');

var argv = yargs
const yargs = require('yargs');
const Proboscis = require('../index');
const server = require('../lib/server');
const runner = new Proboscis();
const loader = new Loader();

const argv = yargs
.usage('proboscis -c "echo foo" -c "echo bar"')
.default('help', false)
.describe('help', 'Display this help text.')
Expand Down Expand Up @@ -43,12 +42,12 @@ if (argv.version) {
process.exit(0);
}

var commands = argv.command;
let commands = argv.command;
if (typeof argv.command === 'string') {
commands = [argv.command];
}

var name = argv.name;
let name = argv.name;
if (typeof argv.name === 'string') {
name = [argv.name];
}
Expand All @@ -57,8 +56,7 @@ runner.eventStream
.pipe(es.stringify())
.pipe(process.stdout);

var i = null;
for (i in argv._) {
for (const i in argv._) {
loader.add(argv._[i]);
}

Expand All @@ -68,19 +66,18 @@ if (argv.keepAlive) {

loader.on('error', function(err) {});
loader.add('/etc/proboscis.yaml');
loader.add(process.env['HOME'] + '/.proboscis.yaml');
loader.add(os.homedir() + '/.proboscis.yaml');
loader.add(argv);
loader.load(function(error, config) {
if (config.port) {
config.log = console.log;
server(runner, config);
}
var i = null;
for (i in commands) {
var command = commands[i];
var args = parse(command);
var binary = args.shift();
var commandName = binary;
for (const i in commands) {
const command = commands[i];
const args = parse(command);
const binary = args.shift();
let commandName = binary;
if (name !== false && name[i] !== undefined) {
commandName = name[i];
}
Expand Down
143 changes: 95 additions & 48 deletions bin/proboscis-control
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#! /usr/bin/env node
var request = require('request'),
util = require('util'),
ev = require('event-stream'),
parse = require('shell-quote').parse,
yargs = require('yargs'),
Loader = require('yaml-config-loader')
prettyjson = require('prettyjson');

var usage = 'proboscis-control [command] [process]';
'use strict';

const util = require('util');
const parse = require('shell-quote').parse;
const Loader = require('yaml-config-loader');
const prettyjson = require('prettyjson');

const usage = 'proboscis-control [command] [process]';
let yargs = require('yargs');
yargs = yargs
.usage('Usage proboscis-command [process-name] [subcommand (start, stop, restart, reload, run, or list)] [args]')
.describe('port', 'The port to issue commands against.')
Expand All @@ -19,11 +19,12 @@ yargs = yargs
.alias('help', 'h')
.describe('command', 'Only for use with the `run` subcommand. A command to run.')
.alias('command', 'c');
var argv = yargs.argv;
const argv = yargs.argv;

var loader = new Loader();
const loader = new Loader();
const os = require('os');
loader.add('/etc/proboscis.yaml');
loader.add(process.env['HOME'] + '/.proboscis.yaml');
loader.add(os.homedir() + '/.proboscis.yaml');
loader.add(argv);
loader.on('error', function() {});
loader.load(function(error, config) {
Expand All @@ -37,9 +38,9 @@ loader.load(function(error, config) {
process.exit(1);
}

var baseURL = 'http://' + config.host + ':' + config.port;
const baseURL = 'http://' + config.host + ':' + config.port;

var operation = argv._[0];
const operation = argv._[0];

switch (operation) {
case 'run':
Expand All @@ -50,17 +51,16 @@ loader.load(function(error, config) {
console.error(util.format('You must provide the name of the process as the second arugment when using `%s`', operation));
process.exit(1);
}
else {
var name = argv._[1];
}
}

var options = {
json: true
};
const name = argv._[1];

var genericCallback = function (error, response, body) {
if (error) throw error;
const genericHandler = async function(response) {
if (!response.ok) {
console.error('An error occurred.');
process.exit(1);
}
const body = await response.json();
if (body && body.message) {
console.log(body.message);
}
Expand All @@ -74,66 +74,113 @@ loader.load(function(error, config) {
switch (operation) {

case 'log':
request(baseURL + '/log', { timeout: false }).pipe(process.stdout);
fetch(baseURL + '/log').then(function(response) {
const reader = response.body.getReader();
const decoder = new TextDecoder();
function read() {
reader.read().then(function(result) {
if (result.done) return;
process.stdout.write(decoder.decode(result.value, {stream: true}));
read();
}).catch(function(err) {
console.error('Error reading log stream:', err.message);
process.exit(1);
});
}
read();
}).catch(function(err) {
console.error('Failed to connect:', err.message);
process.exit(1);
});
break;

case 'list':
request(baseURL + '/running-processes', options, function(error, response, body) {
if (error) throw new Error('Could not connect to service');
fetch(baseURL + '/running-processes').then(async function(response) {
if (!response.ok) {
throw new Error('Could not connect to service');
}
const body = await response.json();
console.log(prettyjson.render(body, { noColor: !process.stdout.isTTY }));
}).catch(function(err) {
console.error(err.message);
process.exit(1);
});
break;

case 'run':
if (!config.command) {
let runCommand = config.command;
if (!runCommand) {
if (!config._[2]) {
console.error('--command (-c) is required for use with the run command.');
process.exit(1);
}
else {
var params = arguments = Array.prototype.slice.call(process.argv, 0);
var position = params.indexOf('run') + 2;
config.command = params.splice(position, params.length).join(' ');
const params = Array.prototype.slice.call(process.argv, 0);
const position = params.indexOf('run') + 2;
runCommand = params.splice(position, params.length).join(' ');
}
}
var args = parse(config.command);
var binary = args.shift();
var options = {
url: baseURL + '/running-processes/' + name,
form: {
const runArgs = parse(runCommand);
const binary = runArgs.shift();
fetch(baseURL + '/running-processes/' + name, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
command: binary,
args: args
},
json: true
};
request.post(options, genericCallback);
args: runArgs,
}),
}).then(genericHandler).catch(function(err) {
console.error('Failed to connect:', err.message);
process.exit(1);
});
break;

case 'start':
request.put(baseURL + '/running-processes/' + name, options, genericCallback);
fetch(baseURL + '/running-processes/' + name, {
method: 'PUT',
}).then(genericHandler).catch(function(err) {
console.error('Failed to connect:', err.message);
process.exit(1);
});
break;

case 'stop':
request.del(baseURL + '/running-processes/' + name, options, genericCallback);
fetch(baseURL + '/running-processes/' + name, {
method: 'DELETE',
}).then(genericHandler).catch(function(err) {
console.error('Failed to connect:', err.message);
process.exit(1);
});
break;

case 'restart':
request.del(baseURL + '/running-processes/' + name, options, function(error, response, body) {
genericCallback.apply(this, arguments);
request.post(baseURL + '/running-processes/' + name, options, genericCallback);
fetch(baseURL + '/running-processes/' + name, {
method: 'DELETE',
}).then(async function(response) {
await genericHandler(response);
return fetch(baseURL + '/running-processes/' + name, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({}),
});
}).then(genericHandler).catch(function(err) {
console.error('Failed to connect:', err.message);
process.exit(1);
});
break;

case undefined:
throw new Error(yargs.help());
console.log(yargs.help());
process.exit(1);
break;

default:
throw new Error(util.format('Unsupoorted operation `%s`', operation));
console.error(util.format('Unsupported operation `%s`', operation));
process.exit(1);
}
}
catch (Error) {
console.log(Error.message);
catch (err) {
console.error(err.message);
process.exit(1);
}
});
26 changes: 14 additions & 12 deletions bin/proboscis-format
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#! /usr/bin/env node
var util = require('util');
var es = require('event-stream');
var yargs = require('yargs');
var formatter = require('json-stream-formatter');
'use strict';

var filter = require('../test/helpers/filter');
const es = require('event-stream');
const yargs = require('yargs');
const jsonFormatter = require('json-stream-formatter');

argv = yargs
const filter = require('../test/helpers/filter');

const argv = yargs
.usage('proboscis -c "echo foo" -c "echo bar" | proboscis-format')
.describe('help', 'Display this help text.')
.default('help', false)
Expand All @@ -22,31 +23,32 @@ argv = yargs
.check(function(argv) {
if (argv.hasOwnProperty('stream') && argv.stream) {
if (['stdout', 'stderr'].indexOf(argv.stream) === -1) {
throw('Invalid stream selected. Options are stdout and stderr.');
throw new Error('Invalid stream selected. Options are stdout and stderr.');
}
}
return true;
})
.default('stream', false)
.argv;

if (argv.help) {
console.log("Format log event streams generated by proboscis in a human readable format.\n\r")
console.log("Format log event streams generated by proboscis in a human readable format.\n\r");
yargs.showHelp();
process.exit(0);
}

var format = null;
let format = null;
if (argv.color !== 'false' && argv.color !== false) {
format = '[{{ time | date("d/m/Y-h:m:s") | cyan }} {{ name | grey }} {{ stream }}] {{ message }}';
}
else {
format = '[{{ time | date("d/m/Y-h:m:s") }} {{ name }} {{ stream }}] {{ message }}';
}
var formatter = formatter.format(format)
const formatter = jsonFormatter.format(format);

var parsed = process.stdin
let parsed = process.stdin
.pipe(es.split())
.pipe(es.parse())
.pipe(es.parse());

if (argv.name) {
parsed = parsed.pipe(filter({name: argv.name}));
Expand Down
Loading