From e43078ce90ea67de9fa4f9ef31c996a96db7f5ef Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 24 May 2018 10:25:32 -0400 Subject: [PATCH] detect swarm started signal --- lib/processes/storageProcesses/swarm.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/processes/storageProcesses/swarm.js b/lib/processes/storageProcesses/swarm.js index b72e30c7b..78e210e70 100644 --- a/lib/processes/storageProcesses/swarm.js +++ b/lib/processes/storageProcesses/swarm.js @@ -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}); + } } });