diff --git a/lib/process/processLauncher.js b/lib/process/processLauncher.js index 15a9f95a..450a3600 100644 --- a/lib/process/processLauncher.js +++ b/lib/process/processLauncher.js @@ -1,6 +1,6 @@ const child_process = require('child_process'); const constants = require('../constants'); - +const path = require('path'); class ProcessLauncher { @@ -14,11 +14,13 @@ class ProcessLauncher { * @return {ProcessLauncher} The ProcessLauncher instance */ constructor(options) { + this.name = path.basename(options.modulePath); this.process = child_process.fork(options.modulePath); this.logger = options.logger; this.normalizeInput = options.normalizeInput; this.events = options.events; this.silent = options.silent; + this.exitCallback = options.exitCallback; this.subscriptions = {}; this._subscribeToMessages(); @@ -38,7 +40,12 @@ class ProcessLauncher { }); this.process.on('exit', (code) => { - self.logger.info('Process exited with code ' + code); + if (self.exitCallback) { + return self.exitCallback(code); + } + if (code) { + this.logger.info(`Child Process ${this.name} exited with code ${code}`); + } }); } diff --git a/lib/processes/blockchainProcessLauncher.js b/lib/processes/blockchainProcessLauncher.js index 9b089d76..7cf79711 100644 --- a/lib/processes/blockchainProcessLauncher.js +++ b/lib/processes/blockchainProcessLauncher.js @@ -12,6 +12,10 @@ class BlockchainProcessLauncher { this.locale = options.locale; } + processEnded(code) { + this.logger.error('Blockchain process ended before the end of this process. Code: ' + code); + } + startBlockchainNode() { this.logger.info('Starting Blockchain node in another process'.cyan); @@ -20,7 +24,8 @@ class BlockchainProcessLauncher { logger: this.logger, events: this.events, normalizeInput: this.normalizeInput, - silent: true + silent: true, + exitCallback: this.processEnded.bind(this) }); this.blockchainProcess.send({ action: constants.blockchain.init, options: {