Browse Source

Merge pull request #26 from pbca26/master

added debug log read function
all-modes
Satinder Grewal 8 years ago
committed by GitHub
parent
commit
81a4173e14
  1. 2
      main.js
  2. 10
      private/mainmenu.js
  3. 95
      routes/shepherd.js

2
main.js

@ -50,7 +50,7 @@ process.once('loaded', () => {
}); });
guiapp.use(bodyParser.json()); // support json encoded bodies guiapp.use(bodyParser.json()); // support json encoded bodies
guiapp.use(bodyParser.urlencoded({ extended: false })); // support encoded bodies guiapp.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
guiapp.get('/', function (req, res) { guiapp.get('/', function (req, res) {
res.send('Iguana app server'); res.send('Iguana app server');

10
private/mainmenu.js

@ -44,7 +44,7 @@ const template = [
accelerator: 'CmdOrCtrl+R', accelerator: 'CmdOrCtrl+R',
click (item, focusedWindow) { click (item, focusedWindow) {
if (focusedWindow) if (focusedWindow)
focusedWindow.reload() focusedWindow.reload();
} }
}, },
{ {
@ -52,7 +52,7 @@ const template = [
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I', accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click (item, focusedWindow) { click (item, focusedWindow) {
if (focusedWindow) if (focusedWindow)
focusedWindow.webContents.toggleDevTools() focusedWindow.webContents.toggleDevTools();
} }
}, },
{ {
@ -96,7 +96,7 @@ const template = [
if (process.platform === 'linux') { if (process.platform === 'linux') {
require('child_process').exec('xdg-open http://support.supernet.org'); require('child_process').exec('xdg-open http://support.supernet.org');
} else { } else {
shell.openExternal('http://support.supernet.org') shell.openExternal('http://support.supernet.org');
} }
} }
}, },
@ -106,7 +106,7 @@ const template = [
if (process.platform === 'linux') { if (process.platform === 'linux') {
require('child_process').exec('xdg-open https://sprnt.slack.com/messages/support'); require('child_process').exec('xdg-open https://sprnt.slack.com/messages/support');
} else { } else {
shell.openExternal('https://sprnt.slack.com/messages/support') shell.openExternal('https://sprnt.slack.com/messages/support');
} }
} }
}, },
@ -116,7 +116,7 @@ const template = [
if (process.platform === 'linux') { if (process.platform === 'linux') {
require('child_process').exec('xdg-open https://github.com/SuperNETorg/iguana/issues'); require('child_process').exec('xdg-open https://github.com/SuperNETorg/iguana/issues');
} else { } else {
shell.openExternal('https://github.com/SuperNETorg/iguana/issues') shell.openExternal('https://github.com/SuperNETorg/iguana/issues');
} }
} }
} }

95
routes/shepherd.js

@ -80,11 +80,39 @@ shepherd.get('/', function(req, res, next) {
}); });
shepherd.get('/appconf', function(req, res, next) { shepherd.get('/appconf', function(req, res, next) {
shepherd.readDebugLog();
var obj = shepherd.loadLocalConfig(); var obj = shepherd.loadLocalConfig();
res.send(obj); res.send(obj);
}); });
shepherd.post('/debuglog', function(req, res) {
var _herd = req.body.herdname,
_lastNLines = req.body.lastLines,
_location;
if (_herd === 'iguana') {
_location = iguanaDir;
} else if (_herd === 'komodo') {
_location = komodoDir;
}
shepherd.readDebugLog(_location + '/debug.log', _lastNLines)
.then(function(result) {
var _obj = {
'msg': 'success',
'result': result
};
res.end(JSON.stringify(_obj));
}, function(result) {
var _obj = {
'msg': 'error',
'result': result
};
res.end(JSON.stringify(_obj));
});
});
shepherd.post('/herd', function(req, res) { shepherd.post('/herd', function(req, res) {
console.log('======= req.body ======='); console.log('======= req.body =======');
//console.log(req); //console.log(req);
@ -94,7 +122,12 @@ shepherd.post('/herd', function(req, res) {
herder(req.body.herd, req.body.options); herder(req.body.herd, req.body.options);
res.end('{ "msg": "success", "result": "result" }'); var obj = {
'msg': 'success',
'result': 'result'
};
res.end(JSON.stringify(obj));
}); });
shepherd.post('/herdlist', function(req, res) { shepherd.post('/herdlist', function(req, res) {
@ -115,7 +148,13 @@ shepherd.post('/herdlist', function(req, res) {
console.log(list[0].pm2_env.status) // print status of IGUANA proc console.log(list[0].pm2_env.status) // print status of IGUANA proc
console.log(list[0].pid) // print pid of IGUANA proc console.log(list[0].pid) // print pid of IGUANA proc
res.end('{ "herdname": ' + req.body.herdname + ', "status": ' + list[0].pm2_env.status + ', "pid": ' + list[0].pid + '}'); var obj = {
'herdname': req.body.herdname,
'status': list[0].pm2_env.status,
'pid': list[0].pid
};
res.end(JSON.stringify(obj));
}); });
}); });
}); });
@ -127,7 +166,12 @@ shepherd.post('/slay', function(req, res) {
//console.log(req.body.slay); //console.log(req.body.slay);
slayer(req.body.slay); slayer(req.body.slay);
res.end('{ "msg": "success", "result": "result" }'); var obj = {
'msg': 'success',
'result': 'result'
};
res.end(JSON.stringify(obj));
}); });
shepherd.post('/setconf', function(req, res) { shepherd.post('/setconf', function(req, res) {
@ -137,7 +181,12 @@ shepherd.post('/setconf', function(req, res) {
//console.log(req.body.chain); //console.log(req.body.chain);
setConf(req.body.chain); setConf(req.body.chain);
res.end('{ "msg": "success", "result": "result" }'); var obj = {
'msg': 'success',
'result': 'result'
};
res.end(JSON.stringify(obj));
}); });
shepherd.post('/getconf', function(req, res) { shepherd.post('/getconf', function(req, res) {
@ -149,7 +198,12 @@ shepherd.post('/getconf', function(req, res) {
var confpath = getConf(req.body.chain); var confpath = getConf(req.body.chain);
console.log('got conf path is:'); console.log('got conf path is:');
console.log(confpath); console.log(confpath);
res.end('{ "msg": "success", "result": "' + confpath + '" }'); var obj = {
'msg': 'success',
'result': confpath
};
res.end(JSON.stringify(obj));
}); });
shepherd.loadLocalConfig = function() { shepherd.loadLocalConfig = function() {
@ -193,13 +247,24 @@ shepherd.loadLocalConfig = function() {
} }
}; };
shepherd.readDebugLog = function() { shepherd.readDebugLog = function(fileLocation, lastNLines) {
console.log('reading debug.log'); return new Promise(
console.log(komodoDir + '/debug.log'); function(resolve, reject) {
if (lastNLines) {
if (fs.existsSync(fileLocation)) {
console.log('reading ' + fileLocation);
readLastLines readLastLines
.read(komodoDir + '/debug.log', 50) .read(fileLocation, lastNLines)
.then((lines) => console.log(lines)); .then((lines) => resolve(lines));
} else {
reject('file ' + fileLocation + ' doesn\'t exist!');
}
} else {
reject('readDebugLog error: lastNLines param is not provided!');
}
}
);
}; };
function herder(flock, data) { function herder(flock, data) {
@ -271,7 +336,7 @@ function herder(flock, data) {
script: iguanaBin, // path to binary script: iguanaBin, // path to binary
name: 'IGUANA', name: 'IGUANA',
exec_mode : 'fork', exec_mode : 'fork',
cwd: iguanaDir, //set correct iguana directory cwd: iguanaDir //set correct iguana directory
}, function(err, apps) { }, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2 pm2.disconnect(); // Disconnect from PM2
if (err) if (err)
@ -295,7 +360,7 @@ function herder(flock, data) {
name: data.ac_name, // REVS, USD, EUR etc. name: data.ac_name, // REVS, USD, EUR etc.
exec_mode : 'fork', exec_mode : 'fork',
cwd: komodoDir, cwd: komodoDir,
args: data.ac_options, args: data.ac_options
//args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas //args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas
}, function(err, apps) { }, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2 pm2.disconnect(); // Disconnect from PM2
@ -317,9 +382,9 @@ function herder(flock, data) {
pm2.start({ pm2.start({
script: CorsProxyBin, // path to binary script: CorsProxyBin, // path to binary
name: 'CORSPROXY', // REVS, USD, EUR etc. name: 'CORSPROXY',
exec_mode : 'fork', exec_mode : 'fork',
cwd: iguanaDir, cwd: iguanaDir
}, function(err, apps) { }, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2 pm2.disconnect(); // Disconnect from PM2
if (err) if (err)

Loading…
Cancel
Save