logs: use child_process.spawn directly for sudo
shell.sudo will move to a promise based API shortly
This commit is contained in:
+12
-6
@@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const assert = require('assert'),
|
const assert = require('assert'),
|
||||||
|
child_process = require('child_process'),
|
||||||
|
debug = require('debug')('box:logs'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
shell = require('./shell.js')('logs'),
|
|
||||||
spawn = require('child_process').spawn,
|
|
||||||
stream = require('stream'),
|
stream = require('stream'),
|
||||||
{ StringDecoder } = require('string_decoder'),
|
{ StringDecoder } = require('string_decoder'),
|
||||||
TransformStream = stream.Transform;
|
TransformStream = stream.Transform;
|
||||||
@@ -64,14 +64,20 @@ function tail(filePaths, options) {
|
|||||||
assert.strictEqual(typeof options, 'object');
|
assert.strictEqual(typeof options, 'object');
|
||||||
|
|
||||||
const lines = options.lines === -1 ? '+1' : options.lines;
|
const lines = options.lines === -1 ? '+1' : options.lines;
|
||||||
const args = options.sudo ? [ LOGTAIL_CMD ] : [];
|
const args = [ `--lines=${lines}` ];
|
||||||
args.push(`--lines=${lines}`);
|
|
||||||
if (options.follow) args.push('--follow');
|
if (options.follow) args.push('--follow');
|
||||||
|
|
||||||
if (options.sudo) {
|
if (options.sudo) {
|
||||||
return shell.sudo(args.concat(filePaths), { quiet: true }, () => {});
|
const cp = child_process.spawn('/usr/bin/sudo', [ '-S', LOGTAIL_CMD, ...args, ...filePaths ]);
|
||||||
|
cp.terminate = () => { // see note in shell.js
|
||||||
|
child_process.spawn('kill', ['-SIGKILL', -cp.pid], { detached: true }, (error) => {
|
||||||
|
if (error) debug(`tail could not terminate`, error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
cp.stdin.end();
|
||||||
|
return cp;
|
||||||
} else {
|
} else {
|
||||||
const cp = spawn('/usr/bin/tail', args.concat(filePaths));
|
const cp = child_process.spawn('/usr/bin/tail', args.concat(filePaths));
|
||||||
cp.terminate = () => cp.kill('SIGKILL');
|
cp.terminate = () => cp.kill('SIGKILL');
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user