diff --git a/lib/modules/swarm/index.js b/lib/modules/swarm/index.js index fd7c3c54f..69387916b 100644 --- a/lib/modules/swarm/index.js +++ b/lib/modules/swarm/index.js @@ -29,6 +29,14 @@ class Swarm { this.setServiceCheck(); this.addProviderToEmbarkJS(); this.startProcess(() => {}); + + this._checkService((err) => { + if (!err) { + return; + } + self.logger.info("Swarm node not found, attempting to start own node"); + self.startProcess(() => {}); + }); } commandlineDeploy() { @@ -64,16 +72,23 @@ class Swarm { self.events.request("services:register", 'Swarm', function(cb){ self.logger.trace(`Checking Swarm availability on ${self.bzz.currentProvider}...`); - self.bzz.isAvailable().then(result => { - self.logger.trace("Swarm " + (result ? '':'un') + "available"); + self._checkService((err, result) => { + if (err) { + self.logger.trace("Check Swarm availability error: " + err); + return cb({name: "Swarm ", status: 'off'}); + } + self.logger.trace("Swarm " + (result ? '':'on') + "available"); return cb({name: "Swarm ", status: result ? 'on':'off'}); - }).catch(err => { - self.logger.trace("Check Swarm availability error: " + err); - return cb({name: "Swarm ", status: 'off'}); - }); + }); }); } + _checkService(cb) { + this.bzz.isAvailable().then(result => { + cb(null, result); + }).catch(cb); + } + addProviderToEmbarkJS() { // TODO: make this a shouldAdd condition if (this.storageConfig === {}) {