detect swarm started signal

This commit is contained in:
Jonathan Rainville 2018-05-24 10:25:32 -04:00
parent 12525fb9bf
commit e43078ce90
1 changed files with 19 additions and 2 deletions

View File

@ -15,7 +15,7 @@ class SwarmProcess extends ProcessWrapper {
if (!this.storageConfig.account || !this.storageConfig.account.address || !this.storageConfig.account.password) {
return 'Account address and password are needed in the storage config to start the Swarm process';
}
shelljs.exec(
const child = shelljs.exec(
`${this.storageConfig.swarmPath || 'swarm'} --bzzaccount ${this.storageConfig.account.address} --password ${this.storageConfig.account.password} --corsdomain http://localhost:8000 --ens-api ''`,
{silent: true}, (err, _stdout, _stderr) =>
{
@ -25,6 +25,21 @@ class SwarmProcess extends ProcessWrapper {
}
process.exit();
});
let lastMessage;
child.stdout.on('data', (data) => {
if (!self.readyCalled && data.indexOf('Swarm http proxy started') > -1) {
self.readyCalled = true;
self.send({result: constants.storage.initiated});
}
lastMessage = data;
console.log('Swarm: ' + data);
});
child.on('exit', (code) => {
if (code) {
console.error('Swarm exited with error code ' + code);
console.error(lastMessage);
}
});
}
}
@ -33,6 +48,8 @@ process.on('message', (msg) => {
swarmProcess = new SwarmProcess(msg.options);
const error = swarmProcess.startSwarmDaemon();
swarmProcess.send({result: constants.storage.initiated, error});
if (error) {
swarmProcess.send({result: constants.storage.initiated, error});
}
}
});