mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 14:24:24 +00:00
refactor service check
This commit is contained in:
parent
e569c08953
commit
0e502c1537
@ -50,37 +50,17 @@ class IPFS {
|
||||
self.logger.info('IPFS node is offline..');
|
||||
});
|
||||
|
||||
let server = 'http://' + this.host + ':' + this.port;
|
||||
self.logger.info(server);
|
||||
|
||||
this.addCheck('IPFS', function (cb) {
|
||||
utils.checkIsAvailable(server, function (available) {
|
||||
if (available) {
|
||||
//Ideally this method should be in an IPFS API JSONRPC wrapper
|
||||
//The URL should also be flexible to accept non-default IPFS url
|
||||
self.logger.trace("Checking IPFS version...");
|
||||
utils.httpGet(server + '/api/v0/version', function (err, body) {
|
||||
if (err) {
|
||||
self.logger.trace("Check IPFS version error: " + err);
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
try {
|
||||
let parsed = JSON.parse(body);
|
||||
if (parsed.Version) {
|
||||
return cb({name: ("IPFS " + parsed.Version), status: 'on'});
|
||||
}
|
||||
else {
|
||||
return cb({name: "IPFS ", status: 'on'});
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
self.logger.trace("Checking IPFS version...");
|
||||
utils.httpGetJson('http://' + this.host + ':' + this.port + '/api/v0/version', function (err, body) {
|
||||
if (err) {
|
||||
self.logger.trace("Check IPFS version error: " + err);
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
if (body.Version) {
|
||||
return cb({name: ("IPFS " + body.Version), status: 'on'});
|
||||
}
|
||||
return cb({name: "IPFS ", status: 'on'});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -56,6 +56,17 @@ function httpsGet(url, callback) {
|
||||
httpGetRequest(https, url, callback);
|
||||
}
|
||||
|
||||
function httpGetJson(url, callback) {
|
||||
httpGetRequest(http, url, function(err, body) {
|
||||
try {
|
||||
let parsed = JSON.parse(body);
|
||||
return callback(err, parsed);
|
||||
} catch(e) {
|
||||
return callback(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function runCmd(cmd, options) {
|
||||
let result = shelljs.exec(cmd, options || {silent: true});
|
||||
if (result.code !== 0) {
|
||||
@ -120,6 +131,7 @@ module.exports = {
|
||||
checkIsAvailable: checkIsAvailable,
|
||||
httpGet: httpGet,
|
||||
httpsGet: httpsGet,
|
||||
httpGetJson: httpGetJson,
|
||||
runCmd: runCmd,
|
||||
cd: cd,
|
||||
sed: sed,
|
||||
|
Loading…
x
Reference in New Issue
Block a user