From 888e330ab9d4ba93c21288187efcd879b4e33f75 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Sun, 28 Jan 2018 15:49:25 +1300 Subject: [PATCH 1/5] feat: ignore subcomandante and use child_process --- src/subcomandante-lite.js | 45 +++++++++++++++++++++++++++++++++++++++ src/utils/exec.js | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/subcomandante-lite.js diff --git a/src/subcomandante-lite.js b/src/subcomandante-lite.js new file mode 100644 index 00000000..fc0b228a --- /dev/null +++ b/src/subcomandante-lite.js @@ -0,0 +1,45 @@ +'use strict' + +const runner = require('child_process') +const debug = require('debug')('subchild') + +const children = [] + +function removeChild (child) { + const i = children.indexOf(child) + if (i !== -1) { + children.slice(i, 1) + } +} + +function killAll () { + debug('killing all children') + let child + while((child = children.shift()) !== undefined) { + debug(child.pid, 'killing') + child.kill(); + } +} + +process.once('error', killAll) +process.once('exit', killAll) +process.once('SIGTERM', killAll) +process.once('SIGINT', killAll) + +function run (cmd, args, opts) { + const child = runner.execFile(cmd, args, opts) + debug(child.pid, 'new') + + children.push(child); + child.once('error', () => { + debug(child.pid, 'error') + removeChild(child) + }) + child.once('exit', () => { + debug(child.pid, 'exit') + removeChild(child); + }) + return child +} + +module.exports = run \ No newline at end of file diff --git a/src/utils/exec.js b/src/utils/exec.js index 233b99cc..0ded8054 100644 --- a/src/utils/exec.js +++ b/src/utils/exec.js @@ -1,6 +1,6 @@ 'use strict' -const run = require('subcomandante') +const run = require('./subcomandante-lite') const once = require('once') const debug = require('debug') const log = debug('ipfsd-ctl:exec') From 8e4ea4aff47fdef1263eb3ae3105a1735d241aff Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Sun, 28 Jan 2018 16:14:56 +1300 Subject: [PATCH 2/5] chore: liniting --- src/subcomandante-lite.js | 90 +++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/subcomandante-lite.js b/src/subcomandante-lite.js index fc0b228a..0b2edc09 100644 --- a/src/subcomandante-lite.js +++ b/src/subcomandante-lite.js @@ -1,45 +1,45 @@ -'use strict' - -const runner = require('child_process') -const debug = require('debug')('subchild') - -const children = [] - -function removeChild (child) { - const i = children.indexOf(child) - if (i !== -1) { - children.slice(i, 1) - } -} - -function killAll () { - debug('killing all children') - let child - while((child = children.shift()) !== undefined) { - debug(child.pid, 'killing') - child.kill(); - } -} - -process.once('error', killAll) -process.once('exit', killAll) -process.once('SIGTERM', killAll) -process.once('SIGINT', killAll) - -function run (cmd, args, opts) { - const child = runner.execFile(cmd, args, opts) - debug(child.pid, 'new') - - children.push(child); - child.once('error', () => { - debug(child.pid, 'error') - removeChild(child) - }) - child.once('exit', () => { - debug(child.pid, 'exit') - removeChild(child); - }) - return child -} - -module.exports = run \ No newline at end of file +'use strict' + +const runner = require('child_process') +const debug = require('debug')('subchild') + +const children = [] + +function removeChild (child) { + const i = children.indexOf(child) + if (i !== -1) { + children.slice(i, 1) + } +} + +function killAll () { + debug('killing all children') + let child + while ((child = children.shift()) !== undefined) { + debug(child.pid, 'killing') + child.kill() + } +} + +process.once('error', killAll) +process.once('exit', killAll) +process.once('SIGTERM', killAll) +process.once('SIGINT', killAll) + +function run (cmd, args, opts) { + const child = runner.execFile(cmd, args, opts) + debug(child.pid, 'new') + + children.push(child) + child.once('error', () => { + debug(child.pid, 'error') + removeChild(child) + }) + child.once('exit', () => { + debug(child.pid, 'exit') + removeChild(child) + }) + return child +} + +module.exports = run From 0c012a2d5020e4759b93ebde8d478e93a2ab5dae Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Thu, 15 Mar 2018 12:39:17 +1300 Subject: [PATCH 3/5] chore: follow conventions --- src/subcomandante-lite.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/subcomandante-lite.js b/src/subcomandante-lite.js index 0b2edc09..85da609f 100644 --- a/src/subcomandante-lite.js +++ b/src/subcomandante-lite.js @@ -1,7 +1,8 @@ 'use strict' const runner = require('child_process') -const debug = require('debug')('subchild') +const debug = require('debug') +const log = debug('ipfsd-ctl:sclite') const children = [] @@ -13,30 +14,29 @@ function removeChild (child) { } function killAll () { - debug('killing all children') + log('killing all children') let child while ((child = children.shift()) !== undefined) { - debug(child.pid, 'killing') + log(child.pid, 'killing') child.kill() } } -process.once('error', killAll) process.once('exit', killAll) process.once('SIGTERM', killAll) process.once('SIGINT', killAll) function run (cmd, args, opts) { const child = runner.execFile(cmd, args, opts) - debug(child.pid, 'new') + log(child.pid, 'new') children.push(child) child.once('error', () => { - debug(child.pid, 'error') + log(child.pid, 'error') removeChild(child) }) child.once('exit', () => { - debug(child.pid, 'exit') + log(child.pid, 'exit') removeChild(child) }) return child From cc27fe004a42f498754d07ffaf6b0d2107dcb4a5 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 14 Mar 2018 19:33:25 -0700 Subject: [PATCH 4/5] fix: move subcomandante-lite to utils --- src/{ => utils}/subcomandante-lite.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{ => utils}/subcomandante-lite.js (100%) diff --git a/src/subcomandante-lite.js b/src/utils/subcomandante-lite.js similarity index 100% rename from src/subcomandante-lite.js rename to src/utils/subcomandante-lite.js From 5ec714fc9194469345070020e3d78704d683f262 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Sat, 17 Mar 2018 09:43:58 +1300 Subject: [PATCH 5/5] chore: remove subcomandante --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 0778c87d..521b218e 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,6 @@ "safe-json-stringify": "^1.1.0", "shutdown": "^0.3.0", "stream-http": "^2.8.0", - "subcomandante": "^1.0.5", "superagent": "^3.8.2", "truthy": "0.0.1" },