Browse Source

run native only

all-modes
pbca26 8 years ago
parent
commit
81a9a87195
  1. 12
      gui/init.js
  2. 8
      main.js
  3. 89
      routes/shepherd.js

12
gui/init.js

@ -7,11 +7,16 @@ $(document).ready(function() {
animation: 'pulse' animation: 'pulse'
}); });
$('#loading_status_text').text('Starting Iguana daemon...');
GetAppConf(inititalWalletLoading); GetAppConf(inititalWalletLoading);
$('#loading_status_text').text('Starting Wallet. Please wait...');
function inititalWalletLoading(appConf) { function inititalWalletLoading(appConf) {
// run iguana-less mode with no daemons startup
if (appConf && appConf.iguanaLessMode) {
window.createWindow('open');
window.hide();
} else { // run normal mode with 2 iguana instances started prior loading GUI
if (appConf && !appConf.manualIguanaStart) { if (appConf && !appConf.manualIguanaStart) {
StartIguana(); StartIguana();
} }
@ -34,8 +39,6 @@ $(document).ready(function() {
EDEX_DEXgetinfoAll(appConf.skipBasiliskNetworkCheck, appConf.minNotaries, appConf); EDEX_DEXgetinfoAll(appConf.skipBasiliskNetworkCheck, appConf.minNotaries, appConf);
} }
}) })
//var check = Iguana_activehandle();
//console.log(check[0])
}, 2000); }, 2000);
} }
@ -45,4 +48,5 @@ $(document).ready(function() {
startcheck(); startcheck();
} }
}
}); });

8
main.js

@ -196,8 +196,8 @@ function createLoadingWindow() {
// initialise window // initialise window
loadingWindow = new BrowserWindow({ loadingWindow = new BrowserWindow({
width: 500, width: appConfig.iguanaLessMode ? 1 : 500,
height: 300, height: appConfig.iguanaLessMode ? 1 : 300,
frame: false, frame: false,
icon: iguanaIcon icon: iguanaIcon
}); });
@ -307,10 +307,6 @@ function createWindow (status) {
shepherd.dumpCacheBeforeExit(); shepherd.dumpCacheBeforeExit();
shepherd.quitKomodod(); shepherd.quitKomodod();
// if komodod is under heavy load it may not respond to cli stop the first time
setInterval(function() {
shepherd.quitKomodod();
}, 100);
pm2.connect(true, function(err) { pm2.connect(true, function(err) {
console.log('connecting to pm2...'); console.log('connecting to pm2...');

89
routes/shepherd.js

@ -25,6 +25,7 @@ var ps = require('ps-node'),
assetChainPorts = require('./ports.js'), assetChainPorts = require('./ports.js'),
shepherd = express.Router(), shepherd = express.Router(),
iguanaInstanceRegistry = {}, iguanaInstanceRegistry = {},
coindInstanceRegistry = {},
syncOnlyIguanaInstanceInfo = {}, syncOnlyIguanaInstanceInfo = {},
syncOnlyInstanceInterval = -1, syncOnlyInstanceInterval = -1,
guiLog = {}, guiLog = {},
@ -97,7 +98,8 @@ shepherd.appConfig = {
"cli": { "cli": {
"passthru": false, "passthru": false,
"default": false "default": false
} },
"iguanaLessMode": false
}; };
shepherd.writeLog = function(data) { shepherd.writeLog = function(data) {
@ -273,17 +275,30 @@ shepherd.post('/coinslist', function(req, res, next) {
}); });
// TODO: check if komodod is running // TODO: check if komodod is running
shepherd.quitKomodod = function(chain) { shepherd.quitKomodod = function() {
// if komodod is under heavy load it may not respond to cli stop the first time
// exit komodod gracefully // exit komodod gracefully
let coindExitInterval = {};
for (let key in coindInstanceRegistry) {
const chain = key !== 'komodod' ? key : null;
coindExitInterval[key] = setInterval(function() {
console.log('exec ' + komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop'); console.log('exec ' + komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop');
exec(komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop', function(error, stdout, stderr) { exec(komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop', function(error, stdout, stderr) {
console.log(`stdout: ${stdout}`); console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`); console.log(`stderr: ${stderr}`);
if (stdout.indexOf('stopping') > -1) {
clearInterval(coindExitInterval[key]);
}
if (error !== null) { if (error !== null) {
console.log(`exec error: ${error}`); console.log(`exec error: ${error}`);
} }
}); });
}, 100);
}
} }
shepherd.getConf = function(chain) { shepherd.getConf = function(chain) {
@ -803,6 +818,56 @@ shepherd.post('/forks', function(req, res, next) {
}); });
}); });
/*
* type: GET
*
*/
shepherd.get('/InstantDEX/allcoins', function(req, res, next) {
// TODO: if only native return obj
// else query main iguana instance and return combined response
// http://localhost:7778/api/InstantDEX/allcoins?userpass=tmpIgRPCUser@1234
let successObj;
if (Object.keys(iguanaInstanceRegistry).length) {
// call to iguana
} else {
let nativeCoindList = [];
for (let key in coindInstanceRegistry) {
nativeCoindList.push(key === 'komodod' ? 'KMD' : key);
}
successObj = {
'native': nativeCoindList,
'basilisk': [],
'full': []
};
}
console.log(successObj);
res.end(JSON.stringify(successObj));
});
/*
* type: GET
*
*/
shepherd.get('/SuperNET/activehandle', function(req, res, next) {
// TODO: if only native return obj
// else query main iguana instance and return combined response
// http://localhost:7778/api/SuperNET/activehandle?userpass=tmpIgRPCUser@1234
const successObj = {
'pubkey': 'nativeonly',
'result': 'success',
'handle': '',
'status': Object.keys(coindInstanceRegistry).length ? 'unlocked' : 'locked',
'duration': 2507830
};
res.end(JSON.stringify(successObj));
});
/* /*
* type: GET * type: GET
* params: pubkey * params: pubkey
@ -1304,11 +1369,12 @@ function herder(flock, data) {
// Status is 'open' if currently in use or 'closed' if available // Status is 'open' if currently in use or 'closed' if available
if (status === 'closed') { if (status === 'closed') {
// start komodod via exec // start komodod via exec
if (data.ac_name === 'komodod') { //if (data.ac_name === 'komodod') {
const _customParamDict = { const _customParamDict = {
'silent': '&', 'silent': '&',
'reindex': '-reindex', 'reindex': '-reindex',
'change': '-pubkey=' 'change': '-pubkey=',
'datadir': '-datadir='
}; };
let _customParam = ''; let _customParam = '';
@ -1322,7 +1388,12 @@ function herder(flock, data) {
console.log(`exec ${komododBin} ${data.ac_options.join(' ')}${_customParam}`); console.log(`exec ${komododBin} ${data.ac_options.join(' ')}${_customParam}`);
shepherd.writeLog(`exec ${komododBin} ${data.ac_options.join(' ')}${_customParam}`); shepherd.writeLog(`exec ${komododBin} ${data.ac_options.join(' ')}${_customParam}`);
exec(`${komododBin} ${data.ac_options.join(' ')}${_customParam}`, { const isChain = data.ac_name.match(/^[A-Z]*$/);
const coindACParam = isChain ? ` -ac_name=${data.ac_name} ` : '';
console.log('coindAC ' + coindACParam);
coindInstanceRegistry[data.ac_name] = true;
exec(`${komododBin} ${coindACParam}${data.ac_options.join(' ')}${_customParam}`, {
maxBuffer: 1024 * 10000 // 10 mb maxBuffer: 1024 * 10000 // 10 mb
}, function(error, stdout, stderr) { }, function(error, stdout, stderr) {
// console.log('stdout: ' + stdout); // console.log('stdout: ' + stdout);
@ -1335,7 +1406,7 @@ function herder(flock, data) {
shepherd.writeLog(`exec error: ${error}`); shepherd.writeLog(`exec error: ${error}`);
} }
}); });
} else { /*} else {
pm2.connect(true, function(err) { // start up pm2 god pm2.connect(true, function(err) { // start up pm2 god
if (err) { if (err) {
console.error(err); console.error(err);
@ -1356,7 +1427,7 @@ function herder(flock, data) {
throw err; throw err;
}); });
}); });
} }*/
} else { } else {
console.log(`port ${_port} (${data.ac_name}) is already in use`); console.log(`port ${_port} (${data.ac_name}) is already in use`);
shepherd.writeLog(`port ${_port} (${data.ac_name}) is already in use`); shepherd.writeLog(`port ${_port} (${data.ac_name}) is already in use`);
@ -1554,7 +1625,7 @@ function setConf(flock) {
fs.readFile(DaemonConfPath, 'utf8', function(err, data) { fs.readFile(DaemonConfPath, 'utf8', function(err, data) {
if (err) { if (err) {
shepherd.writeLog(`setconf error '${err}`); shepherd.writeLog(`setconf error ${err}`);
return console.log(err); return console.log(err);
} }
@ -1777,7 +1848,7 @@ function formatBytes(bytes, decimals) {
return '0 Bytes'; return '0 Bytes';
const k = 1000, const k = 1000,
dm = decimals + 1 || 3, dm = (decimals + 1) || 3,
sizes = [ sizes = [
'Bytes', 'Bytes',
'KB', 'KB',

Loading…
Cancel
Save