mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-05 11:54:02 +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..');
|
self.logger.info('IPFS node is offline..');
|
||||||
});
|
});
|
||||||
|
|
||||||
let server = 'http://' + this.host + ':' + this.port;
|
|
||||||
self.logger.info(server);
|
|
||||||
|
|
||||||
this.addCheck('IPFS', function (cb) {
|
this.addCheck('IPFS', function (cb) {
|
||||||
utils.checkIsAvailable(server, function (available) {
|
self.logger.trace("Checking IPFS version...");
|
||||||
if (available) {
|
utils.httpGetJson('http://' + this.host + ':' + this.port + '/api/v0/version', function (err, body) {
|
||||||
//Ideally this method should be in an IPFS API JSONRPC wrapper
|
if (err) {
|
||||||
//The URL should also be flexible to accept non-default IPFS url
|
self.logger.trace("Check IPFS version error: " + err);
|
||||||
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 {
|
|
||||||
return cb({name: "IPFS ", status: 'off'});
|
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);
|
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) {
|
function runCmd(cmd, options) {
|
||||||
let result = shelljs.exec(cmd, options || {silent: true});
|
let result = shelljs.exec(cmd, options || {silent: true});
|
||||||
if (result.code !== 0) {
|
if (result.code !== 0) {
|
||||||
@ -120,6 +131,7 @@ module.exports = {
|
|||||||
checkIsAvailable: checkIsAvailable,
|
checkIsAvailable: checkIsAvailable,
|
||||||
httpGet: httpGet,
|
httpGet: httpGet,
|
||||||
httpsGet: httpsGet,
|
httpsGet: httpsGet,
|
||||||
|
httpGetJson: httpGetJson,
|
||||||
runCmd: runCmd,
|
runCmd: runCmd,
|
||||||
cd: cd,
|
cd: cd,
|
||||||
sed: sed,
|
sed: sed,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user