Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_launchKiller(parentPid: number, childPid: number): ChildProcess {
this.debug(`Called MongoInstance._launchKiller(parent: ${parentPid}, child: ${childPid}):`);
// spawn process which kills itself and mongo process if current process is dead
const killer = spawnChild(
process.argv[0],
[
path.resolve(__dirname, '../../scripts/mongo_killer.js'),
parentPid.toString(),
childPid.toString(),
],
{ stdio: 'pipe' }
);
['exit', 'message', 'disconnect', 'error'].forEach((e) => {
killer.on(e, (...args) => {
this.debug(`[MongoKiller]: ${e} - ${JSON.stringify(args)}`);
});
});
return killer;
_launchMongod(mongoBin: string): ChildProcess {
const spawnOpts = this.opts.spawn || {};
if (!spawnOpts.stdio) spawnOpts.stdio = 'pipe';
const childProcess = spawnChild(mongoBin, this.prepareCommandArgs(), spawnOpts);
if (childProcess.stderr) {
childProcess.stderr.on('data', this.stderrHandler.bind(this));
}
if (childProcess.stdout) {
childProcess.stdout.on('data', this.stdoutHandler.bind(this));
}
childProcess.on('close', this.closeHandler.bind(this));
childProcess.on('error', this.errorHandler.bind(this));
return childProcess;
}