diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index 787e1de31..851aa0cec 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -125,7 +125,7 @@ Blockchain.prototype.run = function() { }); child.on('exit', (code) => { if (code) { - console.error('Geth exited with error code ' + 1); + console.error('Geth exited with error code ' + code); console.error(lastMessage); } }); diff --git a/lib/i18n/locales/en.json b/lib/i18n/locales/en.json index 0621f4e24..b97a51445 100644 --- a/lib/i18n/locales/en.json +++ b/lib/i18n/locales/en.json @@ -135,6 +135,8 @@ "deploying to swarm!": "deploying to swarm!", "adding %s to swarm": "adding %s to swarm", "error uploading to swarm": "error uploading to swarm", + "Starting ipfs process": "Starting ipfs process", + "Storage process for ipfs ended before the end of this process. Code: 0": "Storage process for ipfs ended before the end of this process. Code: 0", "WARNING! DApp path length is too long: ": "WARNING! DApp path length is too long: ", "This is known to cause issues with starting geth, please consider reducing your DApp path's length to 66 characters or less.": "This is known to cause issues with starting geth, please consider reducing your DApp path's length to 66 characters or less.", "Installing packages...": "Installing packages...", @@ -143,4 +145,4 @@ "For more info go to http://embark.status.im": "For more info go to http://embark.status.im", "%s is not installed on your machine": "%s is not installed on your machine", "You can install it by visiting: %s": "You can install it by visiting: %s" -} \ No newline at end of file +} diff --git a/lib/index.js b/lib/index.js index d511e9ffa..bd28acb53 100644 --- a/lib/index.js +++ b/lib/index.js @@ -335,8 +335,19 @@ class Embark { if (!checkFn || typeof checkFn.fn !== 'function') { return callback(); } - checkFn.fn(function (serviceCheckResult) { - if (!serviceCheckResult.status || serviceCheckResult.status === 'off') { + + const erroObj = {message: __('Cannot upload: {{platform}} node is not running on {{protocol}}://{{host}}:{{port}}.', {platform: platform, protocol: engine.config.storageConfig.protocol, host: engine.config.storageConfig.host, port: engine.config.storageConfig.port})}; + function checkEndpoint(cb) { + checkFn.fn(function (serviceCheckResult) { + if (!serviceCheckResult.status || serviceCheckResult.status === 'off') { + return cb(erroObj); + } + cb(); + }); + } + + checkEndpoint(function (err) { + if (err) { const storageProcessesLauncher = new StorageProcessesLauncher({ logger: engine.logger, events: engine.events, @@ -345,9 +356,15 @@ class Embark { return storageProcessesLauncher.launchProcess(platform.toLowerCase(), (err) => { if (err) { engine.logger.error(err); - return callback({message: __('Cannot upload: {{platform}} node is not running on {{protocol}}://{{host}}:{{port}}.', {platform: platform, protocol: engine.config.storageConfig.protocol, host: engine.config.storageConfig.host, port: engine.config.storageConfig.port})}); + return callback(erroObj); } - callback(); + // Check endpoint again to see if really did start + checkEndpoint((err) => { + if (err) { + return callback(err); + } + callback(); + }); }); } callback(); diff --git a/lib/processes/storageProcesses/ipfs.js b/lib/processes/storageProcesses/ipfs.js index 36202b4da..dba1b62f8 100644 --- a/lib/processes/storageProcesses/ipfs.js +++ b/lib/processes/storageProcesses/ipfs.js @@ -2,7 +2,7 @@ const shelljs = require('shelljs'); const ProcessWrapper = require('../../process/processWrapper'); const constants = require('../../constants'); -let ipfsProcess; +let ipfsProcess; // eslint-disable-line no-unused-vars class IPFSProcess extends ProcessWrapper { constructor(_options) { @@ -12,19 +12,34 @@ class IPFSProcess extends ProcessWrapper { } startIPFSDaemon() { - shelljs.exec('ipfs daemon', {silent: true}, (err, _stdout, _stderr) => { + const self = this; + const child = shelljs.exec('ipfs daemon', {silent: true}, (err, _stdout, _stderr) => { if (err) { console.error(err); process.exit(1); } process.exit(); }); + let lastMessage; + child.stdout.on('data', (data) => { + if (!self.readyCalled && data.indexOf('Daemon is ready') > -1) { + self.readyCalled = true; + self.send({result: constants.storage.initiated}); + } + lastMessage = data; + console.log('IPFS: ' + data); + }); + child.on('exit', (code) => { + if (code) { + console.error('IPFS exited with error code ' + code); + console.error(lastMessage); + } + }); } } process.on('message', (msg) => { if (msg.action === constants.storage.init) { ipfsProcess = new IPFSProcess(msg.options); - return ipfsProcess.send({result: constants.storage.initiated}); } }); diff --git a/lib/processes/storageProcesses/swarm.js b/lib/processes/storageProcesses/swarm.js index da1dde2a8..b72e30c7b 100644 --- a/lib/processes/storageProcesses/swarm.js +++ b/lib/processes/storageProcesses/swarm.js @@ -21,11 +21,9 @@ class SwarmProcess extends ProcessWrapper { { if (err) { console.error(err); - //process.exit(1); - return; + process.exit(1); } - console.log('Complete?') - //process.exit(); + process.exit(); }); } }