fix processes on ubuntu

This commit is contained in:
Jonathan Rainville 2018-05-30 10:52:15 -04:00
parent fe34d84ff4
commit 138aaf39ff
6 changed files with 44 additions and 11 deletions

View File

@ -120,9 +120,9 @@ Blockchain.prototype.run = function() {
return;
}
args = _.compact(args);
const child = child_process.spawn(cmd, args, {cwd: process.cwd()});
self.child = child_process.spawn(cmd, args, {cwd: process.cwd()});
child.on('error', (err) => {
self.child.on('error', (err) => {
err = err.toString();
console.error('Blockchain error: ', err);
if (self.env === 'development' && err.indexOf('Failed to unlock') > 0) {
@ -131,19 +131,19 @@ Blockchain.prototype.run = function() {
console.error(__('Otherwise, you can change your data directory in blockchain.json (datadir)').yellow);
}
});
child.stdout.on('data', (data) => {
self.child.stdout.on('data', (data) => {
console.log(`Geth error: ${data}`);
});
// Geth logs appear in stderr somehow
child.stderr.on('data', (data) => {
self.child.stderr.on('data', (data) => {
data = data.toString();
if (self.onReadyCallback && !self.readyCalled && data.indexOf('Mapped network port') > -1) {
if (self.onReadyCallback && !self.readyCalled && data.indexOf('WebSocket endpoint opened') > -1) {
self.readyCalled = true;
self.onReadyCallback();
}
console.log('Geth: ' + data);
});
child.on('exit', (code) => {
self.child.on('exit', (code) => {
if (code) {
console.error('Geth exited with error code ' + code);
}
@ -151,6 +151,12 @@ Blockchain.prototype.run = function() {
});
};
Blockchain.prototype.kill = function() {
if (this.child) {
this.child.kill();
}
};
Blockchain.prototype.checkPathLength = function() {
let dappPath = fs.dappPath('');
if (dappPath.length > 66) {

View File

@ -30,9 +30,16 @@ class BlockchainProcess extends ProcessWrapper {
blockchainReady() {
blockchainProcess.send({result: constants.blockchain.blockchainReady});
}
kill() {
this.blockchain.kill();
}
}
process.on('message', (msg) => {
if (msg === 'exit') {
return blockchainProcess.kill();
}
if (msg.action === constants.blockchain.init) {
blockchainProcess = new BlockchainProcess(msg.options);
return blockchainProcess.send({result: constants.blockchain.initiated});

View File

@ -330,6 +330,7 @@ class Dashboard {
let self = this;
this.input.key(["C-c"], function () {
self.events.emit('exit');
process.exit(0);
});

View File

@ -43,6 +43,10 @@ class BlockchainProcessLauncher {
this.logger.info(__('Blockchain node is ready').cyan);
this.events.emit(constants.blockchain.blockchainReady);
});
this.events.on('exit', () => {
this.blockchainProcess.send('exit');
});
}
}

View File

@ -31,17 +31,17 @@ class IPFSProcess extends ProcessWrapper {
startIPFSDaemon() {
const self = this;
const child = child_process.spawn('ipfs', ['daemon']);
this.child = child_process.spawn('ipfs', ['daemon']);
child.on('error', (err) => {
this.child.on('error', (err) => {
err = err.toString();
console.error('IPFS error: ', err);
});
child.stderr.on('data', (data) => {
this.child.stderr.on('data', (data) => {
data = data.toString();
console.log(`IPFS error: ${data}`);
});
child.stdout.on('data', (data) => {
this.child.stdout.on('data', (data) => {
data = data.toString();
if (!self.readyCalled && data.indexOf('Daemon is ready') > -1) {
self.readyCalled = true;
@ -49,15 +49,24 @@ class IPFSProcess extends ProcessWrapper {
}
console.log('IPFS: ' + data);
});
child.on('exit', (code) => {
this.child.on('exit', (code) => {
if (code) {
console.error('IPFS exited with error code ' + code);
}
});
}
kill() {
if (this.child) {
this.child.kill();
}
}
}
process.on('message', (msg) => {
if (msg === 'exit') {
return ipfsProcess.kill();
}
if (msg.action === constants.storage.init) {
ipfsProcess = new IPFSProcess(msg.options);
}

View File

@ -10,6 +10,12 @@ class StorageProcessesLauncher {
this.storageConfig = options.storageConfig;
this.webServerConfig = options.webServerConfig;
this.processes = {};
this.events.on('exit', () => {
Object.keys(this.processes).forEach(processName => {
this.processes[processName].send('exit');
});
});
}
processExited(storageName, code) {