fix swarm

This commit is contained in:
Jonathan Rainville 2018-05-30 12:58:32 -04:00
parent b5e96beb81
commit 4db2d40ef5
2 changed files with 16 additions and 8 deletions

View File

@ -37,7 +37,7 @@ class StorageProcessesLauncher {
modulePath: filePath,
logger: self.logger,
events: self.events,
silent: true,
silent: false,
exitCallback: self.processExited.bind(this, storageName)
});
self.processes[storageName].send({

View File

@ -25,21 +25,20 @@ class SwarmProcess extends ProcessWrapper {
const args = [
`--bzzaccount=${this.storageConfig.account.address}`,
`--password=${fs.dappPath(this.storageConfig.account.password)}`,
`--corsdomain=${corsDomain}`,
`--ens-api=''`
`--corsdomain=${corsDomain}`
];
const child = child_process.spawn(this.storageConfig.swarmPath || 'swarm', args, {shell: true});
this.child = child_process.spawn(this.storageConfig.swarmPath || 'swarm', args);
child.on('error', (err) => {
this.child.on('error', (err) => {
err = err.toString();
console.error('Swarm error: ', err);
});
child.stdout.on('data', (data) => {
this.child.stdout.on('data', (data) => {
data = data.toString();
console.log(`Swarm error: ${data}`);
});
// Swarm logs appear in stderr somehow
child.stderr.on('data', (data) => {
this.child.stderr.on('data', (data) => {
data = data.toString();
if (!self.readyCalled && data.indexOf('Swarm http proxy started') > -1) {
self.readyCalled = true;
@ -47,15 +46,24 @@ class SwarmProcess extends ProcessWrapper {
}
console.log('Swarm: ' + data);
});
child.on('exit', (code) => {
this.child.on('exit', (code) => {
if (code) {
console.error('Swarm exited with error code ' + code);
}
});
}
kill() {
if (this.child) {
this.child.kill();
}
}
}
process.on('message', (msg) => {
if (msg === 'exit') {
return swarmProcess.kill();
}
if (msg.action === constants.storage.init) {
swarmProcess = new SwarmProcess(msg.options);
const error = swarmProcess.startSwarmDaemon();