Skip to content
Closed
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/exec.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
45 changes: 45 additions & 0 deletions src/utils/subcomandante-lite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict'

const runner = require('child_process')
const debug = require('debug')
const log = debug('ipfsd-ctl:sclite')

const children = []

function removeChild (child) {
const i = children.indexOf(child)
if (i !== -1) {
children.slice(i, 1)
}
}

function killAll () {
log('killing all children')
let child
while ((child = children.shift()) !== undefined) {
log(child.pid, 'killing')
child.kill()
}
}

process.once('exit', killAll)
process.once('SIGTERM', killAll)
process.once('SIGINT', killAll)

function run (cmd, args, opts) {
const child = runner.execFile(cmd, args, opts)
log(child.pid, 'new')

children.push(child)
child.once('error', () => {
log(child.pid, 'error')
removeChild(child)
})
child.once('exit', () => {
log(child.pid, 'exit')
removeChild(child)
})
return child
}

module.exports = run