From 9338b6e37fbdbde335787559e7c4a6acf0de5473 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 28 May 2018 15:37:25 -0400 Subject: [PATCH] fix swarm spawn --- lib/processes/storageProcesses/swarm.js | 31 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/processes/storageProcesses/swarm.js b/lib/processes/storageProcesses/swarm.js index bb720b3aa..1242184a6 100644 --- a/lib/processes/storageProcesses/swarm.js +++ b/lib/processes/storageProcesses/swarm.js @@ -1,6 +1,7 @@ const child_process = require('child_process'); const ProcessWrapper = require('../../process/processWrapper'); const constants = require('../../constants'); +const fs = require('../../core/fs'); let swarmProcess; @@ -20,15 +21,27 @@ class SwarmProcess extends ProcessWrapper { if (self.webServerConfig && self.webServerConfig && self.webServerConfig.host && self.webServerConfig.port) { corsDomain = `http://${self.webServerConfig.host}:${self.webServerConfig.port}`; } - const child = child_process.spawn(this.storageConfig.swarmPath || 'swarm', - [ - `--bzzaccount ${this.storageConfig.account.address}`, - `--password ${this.storageConfig.account.password}`, - `--corsdomain ${corsDomain}`, - "--ens-api ''" - ]); + + const args = [ + `--bzzaccount=${this.storageConfig.account.address}`, + `--password=${fs.dappPath(this.storageConfig.account.password)}`, + `--corsdomain=${corsDomain}`, + `--ens-api=''` + ]; + const child = child_process.spawn(this.storageConfig.swarmPath || 'swarm', args, {shell: true}); + + child.on('error', (err) => { + err = err.toString(); + console.error('Swarm error: ', err); + }); let lastMessage; + child.stdout.on('data', (data) => { + data = data.toString(); + console.log(`Swarm error: ${data}`); + }); + // Geth logs appear in stderr somehow child.stderr.on('data', (data) => { + data = data.toString(); if (!self.readyCalled && data.indexOf('Swarm http proxy started') > -1) { self.readyCalled = true; self.send({result: constants.storage.initiated}); @@ -39,7 +52,9 @@ class SwarmProcess extends ProcessWrapper { child.on('exit', (code) => { if (code) { console.error('Swarm exited with error code ' + code); - console.error(lastMessage); + if (lastMessage) { + console.error(lastMessage); + } } }); }