Browse Source

Merge pull request #25 from pbca26/master

create app config.json in iguana folder
all-modes
Satinder Grewal 8 years ago
committed by GitHub
parent
commit
8b661e251e
  1. 6
      config.json
  2. 4
      gui/index.html
  3. 3
      gui/init.js
  4. 10
      gui/loading.js
  5. 53
      main.js
  6. 3
      package.json
  7. 30
      pull-gui.sh
  8. 151
      routes/shepherd.js

6
config.json

@ -1,6 +0,0 @@
{
"edexGuiOnly": true,
"iguanaGuiOnly": false,
"manualIguanaStart": false,
"skipBasiliskNetworkCheck": false
}

4
gui/index.html

@ -10,10 +10,6 @@
<script type="text/javascript" src="loading.js"></script> <script type="text/javascript" src="loading.js"></script>
<script type="text/javascript" src="jRoll.min.js"></script> <script type="text/javascript" src="jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script> <script>if (window.module) module = window.module;</script>
<script type="text/javascript">
const remote = require('electron').remote;
var window = remote.getCurrentWindow();
</script>>
</head> </head>
<body style="overflow:hidden;"> <body style="overflow:hidden;">
<div style="text-align: center;"> <div style="text-align: center;">

3
gui/init.js

@ -1,4 +1,7 @@
$(document).ready(function() { $(document).ready(function() {
const remote = require('electron').remote;
var window = remote.getCurrentWindow();
$('#pulse').jRoll({ $('#pulse').jRoll({
radius: 100, radius: 100,
animation: 'pulse' animation: 'pulse'

10
gui/loading.js

@ -92,7 +92,7 @@ function EDEX_DEXnotarychains() {
'agent': 'dpow', 'agent': 'dpow',
'method': 'notarychains' 'method': 'notarychains'
}, },
AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778',ajax_data).done(function(data) { AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778', ajax_data).done(function(data) {
//console.log(AjaxOutputData.responseText); //console.log(AjaxOutputData.responseText);
AjaxOutputData = JSON.parse(AjaxOutputData.responseText); AjaxOutputData = JSON.parse(AjaxOutputData.responseText);
//console.log(AjaxOutputData); //console.log(AjaxOutputData);
@ -131,17 +131,17 @@ function EDEX_DEXgetinfoAll() {
'symbol': coin_value 'symbol': coin_value
}, },
basiliskMinNotariesConnected = 10; basiliskMinNotariesConnected = 10;
console.log(ajax_data); console.log(ajax_data);
if (coin_value !== 'MESH' || coin_value !== 'CEAL') { if (coin_value !== 'MESH' || coin_value !== 'CEAL') {
var getinfo_each_chain = IguanaAJAX('http://127.0.0.1:7778', ajax_data).done(function(data) { var getinfo_each_chain = IguanaAJAX('http://127.0.0.1:7778', ajax_data).done(function(data) {
getinfo_each_chain = JSON.parse(getinfo_each_chain.responseText); getinfo_each_chain = JSON.parse(getinfo_each_chain.responseText);
console.log(getinfo_each_chain); console.log(getinfo_each_chain);
tmp_index = parseInt(coin_index) + 1; tmp_index = parseInt(coin_index) + 1;
$('#loading_sub_status_text').text('Connection status... ' + tmp_index + '/' + get_dex_notarychains.length + ': ' + coin_value); $('#loading_sub_status_text').text('Connection status... ' + tmp_index + '/' + get_dex_notarychains.length + ': ' + coin_value);
if (getinfo_each_chain.error === 'less than required responses') { if (getinfo_each_chain.error === 'less than required responses') {
$('#loading_sub_status_output_text').text('Output: ' + getinfo_each_chain.error); $('#loading_sub_status_output_text').text('Output: ' + getinfo_each_chain.error);
} else { } else {
@ -151,7 +151,7 @@ function EDEX_DEXgetinfoAll() {
if ( tmp_index == 10 ) { if ( tmp_index == 10 ) {
console.log('min notaries connected'); console.log('min notaries connected');
const remote = require('electron').remote; const remote = require('electron').remote;
var window = remote.getCurrentWindow(); var window = remote.getCurrentWindow();
window.hide(); window.hide();
} }
}).fail(function(xhr, textStatus, error) { }).fail(function(xhr, textStatus, error) {

53
main.js

@ -3,25 +3,23 @@
const electron = require('electron'), const electron = require('electron'),
app = electron.app, app = electron.app,
BrowserWindow = electron.BrowserWindow; BrowserWindow = electron.BrowserWindow,
var express = require('express'), path = require('path'),
bodyParser = require('body-parser');
const path = require('path'),
url = require('url'), url = require('url'),
os = require('os'), os = require('os'),
spawn = require('child_process').spawn, spawn = require('child_process').spawn,
exec = require('child_process').exec; exec = require('child_process').exec,
var fs = require('fs'), fixPath = require('fix-path');
var express = require('express'),
bodyParser = require('body-parser'),
fs = require('fs'),
fsnode = require('fs'),
fs = require('fs-extra'), fs = require('fs-extra'),
mkdirp = require('mkdirp'), mkdirp = require('mkdirp'),
pm2 = require('pm2'); pm2 = require('pm2');
var iguanaAppPort = 17777;
Promise = require('bluebird'); Promise = require('bluebird');
var appConfig = JSON.parse(fs.readFileSync('config.json', 'utf8'));
app.setName('Iguana'); app.setName('Iguana');
if (os.platform() === 'linux') { if (os.platform() === 'linux') {
@ -29,45 +27,47 @@ if (os.platform() === 'linux') {
console.log(process.env); console.log(process.env);
} }
// GUI APP settings and starting gui on address http://120.0.0.1:17777
var shepherd = require('./routes/shepherd'),
guiapp = express();
var appConfig = shepherd.loadLocalConfig(); // load app config
// preload.js // preload.js
const _setImmediate = setImmediate, const _setImmediate = setImmediate,
_clearImmediate = clearImmediate; _clearImmediate = clearImmediate;
process.once('loaded', () => { process.once('loaded', () => {
global.setImmediate = _setImmediate; global.setImmediate = _setImmediate;
global.clearImmediate = _clearImmediate; global.clearImmediate = _clearImmediate;
if (os.platform() === 'darwin') { if (os.platform() === 'darwin') {
process.setFdLimit(90000); process.setFdLimit(appConfig.maxDescriptors.darwin);
} }
if (os.platform() === 'linux') { if (os.platform() === 'linux') {
process.setFdLimit(1000000); process.setFdLimit(appConfig.maxDescriptors.linux);
} }
}); });
// GUI APP settings and starting gui on address http://120.0.0.1:17777
var shepherd = require('./routes/shepherd'),
guiapp = express();
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: false })); // support encoded bodies
guiapp.get('/', function (req, res) { guiapp.get('/', function (req, res) {
res.send('Iguana app server'); res.send('Iguana app server');
}) });
var guipath = path.join(__dirname, '/gui'); var guipath = path.join(__dirname, '/gui');
guiapp.use('/gui', express.static(guipath)); guiapp.use('/gui', express.static(guipath));
guiapp.use('/shepherd', shepherd); guiapp.use('/shepherd', shepherd);
var rungui = guiapp.listen(iguanaAppPort, function () { var rungui = guiapp.listen(appConfig.iguanaAppPort, function () {
console.log('guiapp listening on port ' + iguanaAppPort + '!'); console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!');
}) })
module.exports = guiapp; module.exports = guiapp;
// END GUI App Settings // END GUI App Settings
//require('./assets/js/iguana.js'); //below code shall be separated into asset js for public version //require('./assets/js/iguana.js'); //below code shall be separated into asset js for public version
/* /*
// SELECTING IGUANA BUILD TO RUN AS PER OS DETECTED BY DESKTOP APP // SELECTING IGUANA BUILD TO RUN AS PER OS DETECTED BY DESKTOP APP
@ -138,7 +138,7 @@ function createLoadingWindow() {
}); });
// load our index.html (i.e. easyDEX GUI) // load our index.html (i.e. easyDEX GUI)
loadingWindow.loadURL('http://127.0.0.1:17777/gui/'); loadingWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/');
// DEVTOOLS - only for dev purposes - ca333 // DEVTOOLS - only for dev purposes - ca333
//loadingWindow.webContents.openDevTools() //loadingWindow.webContents.openDevTools()
@ -171,7 +171,7 @@ function createLoadingWindow() {
//if (os.platform() !== 'win32') { ig.stderr.on( 'error: ', data => { console.log( `stderr: ${data}` ); }); } //if (os.platform() !== 'win32') { ig.stderr.on( 'error: ', data => { console.log( `stderr: ${data}` ); }); }
} }
app.on('ready', createLoadingWindow) app.on('ready', createLoadingWindow);
function createWindow (status) { function createWindow (status) {
if ( status === 'open') { if ( status === 'open') {
@ -187,9 +187,9 @@ function createWindow (status) {
// load our index.html (i.e. easyDEX GUI) // load our index.html (i.e. easyDEX GUI)
if (appConfig.edexGuiOnly) { if (appConfig.edexGuiOnly) {
mainWindow.loadURL('http://127.0.0.1:' + iguanaAppPort + '/gui/EasyDEX-GUI/'); mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/EasyDEX-GUI/');
} else { } else {
mainWindow.loadURL('http://127.0.0.1:' + iguanaAppPort + '/gui/main.html'); mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/main.html');
} }
// DEVTOOLS - only for dev purposes - ca333 // DEVTOOLS - only for dev purposes - ca333
@ -201,7 +201,7 @@ function createWindow (status) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
console.log('Closing Main Window...'); console.log('Closing Main Window...');
pm2.connect(true,function(err) { pm2.connect(true, function(err) {
console.log('connecting to pm2...'); console.log('connecting to pm2...');
if (err) { if (err) {
@ -223,6 +223,7 @@ function createWindow (status) {
pm2.killDaemon(function(err) { pm2.killDaemon(function(err) {
pm2.disconnect(); pm2.disconnect();
console.log('killed to pm2...'); console.log('killed to pm2...');
if (err) if (err)
throw err; throw err;
}); });

3
package.json

@ -32,6 +32,7 @@
"md5": "^2.2.1", "md5": "^2.2.1",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"pm2": "^2.3.0", "pm2": "^2.3.0",
"ps-node": "^0.1.4" "ps-node": "^0.1.4",
"read-last-lines": "^1.1.0"
} }
} }

30
pull-gui.sh

@ -14,25 +14,23 @@ else
git clone https://github.com/SuperNETorg/EasyDEX-GUI.git git clone https://github.com/SuperNETorg/EasyDEX-GUI.git
fi fi
if [ -d "Iguana-application" ]; then #if [ -d "Iguana-application" ]; then
cd Iguana-application # cd Iguana-application
git checkout 0.3.1 # git checkout 0.3.1
git branch 0.3.1 --track origin/0.3.1 # git pull
git pull #else
else # git clone https://github.com/SuperNETorg/Iguana-application.git -b 0.3.1
git clone https://github.com/SuperNETorg/Iguana-application.git -b 0.3.1 # cd Iguana-application
cd Iguana-application #fi
git branch 0.3.1 --track origin/0.3.1
fi
bower install #bower install
npm install #npm install
gulp electron #gulp electron
cd ../../ cd ../../
rm "gui/EasyDEX-GUI" -rf rm "gui/EasyDEX-GUI" -rf
rm "gui/Iguana-GUI" -rf #rm "gui/Iguana-GUI" -rf
cp -rf "tmp/Iguana-application/compiled/prod" "gui/Iguana-GUI" #cp -rf "tmp/Iguana-application/compiled/prod" "gui/Iguana-GUI"
cp -rf "tmp/EasyDEX-GUI" "gui/EasyDEX-GUI" cp -rf "tmp/EasyDEX-GUI" "gui/EasyDEX-GUI"

151
routes/shepherd.js

@ -10,7 +10,8 @@ const electron = require('electron'),
express = require('express'), express = require('express'),
exec = require('child_process').exec, exec = require('child_process').exec,
md5 = require('md5'), md5 = require('md5'),
pm2 = require('pm2'); pm2 = require('pm2'),
readLastLines = require('read-last-lines');
Promise = require('bluebird'); Promise = require('bluebird');
@ -56,18 +57,33 @@ if (os.platform() === 'win32') {
iguanaConfsDirSrc = path.normalize(iguanaConfsDirSrc); iguanaConfsDirSrc = path.normalize(iguanaConfsDirSrc);
} }
console.log(iguanaDir); shepherd.appConfig = {
console.log(iguanaBin); "edexGuiOnly": true,
"iguanaGuiOnly": false,
"manualIguanaStart": false,
"skipBasiliskNetworkCheck": false,
"host": "127.0.0.1",
"iguanaAppPort": 17777,
"iguanaCorePort": 7778,
"maxDescriptors": {
"darwin": 90000,
"linux": 1000000
}
};
console.log('iguana dir: ' + iguanaDir);
console.log('iguana bin: ' + iguanaBin);
// END IGUANA FILES AND CONFIG SETTINGS // END IGUANA FILES AND CONFIG SETTINGS
shepherd.get('/', function(req, res, next) { shepherd.get('/', function(req, res, next) {
res.send('Iguana app server') res.send('Iguana app server');
}) });
shepherd.get('/appconf', function(req, res, next) { shepherd.get('/appconf', function(req, res, next) {
var obj = JSON.parse(fs.readFileSync('config.json', 'utf8')); shepherd.readDebugLog();
var obj = shepherd.loadLocalConfig();
res.send(obj); res.send(obj);
}) });
shepherd.post('/herd', function(req, res) { shepherd.post('/herd', function(req, res) {
console.log('======= req.body ======='); console.log('======= req.body =======');
@ -92,12 +108,13 @@ shepherd.post('/herdlist', function(req, res) {
if (err) throw err; // TODO: proper error handling if (err) throw err; // TODO: proper error handling
pm2.describe(req.body.herdname, function(err, list) { pm2.describe(req.body.herdname, function(err, list) {
pm2.disconnect(); // disconnect after getting proc info list pm2.disconnect(); // disconnect after getting proc info list
if (err) throw err // TODO: proper error handling if (err)
throw err; // TODO: proper error handling
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 + '}'); res.end('{ "herdname": ' + req.body.herdname + ', "status": ' + list[0].pm2_env.status + ', "pid": ' + list[0].pid + '}');
}); });
}); });
@ -130,11 +147,61 @@ shepherd.post('/getconf', function(req, res) {
//console.log(req.body.chain); //console.log(req.body.chain);
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 + '" }'); res.end('{ "msg": "success", "result": "' + confpath + '" }');
}); });
shepherd.loadLocalConfig = function() {
if (fs.existsSync(iguanaDir + '/config.json')) {
var localAppConfig = fs.readFileSync(iguanaDir + '/config.json', 'utf8');
console.log('app config set from local file');
// find diff between local and hardcoded configs
// append diff to local config
var compareJSON = function(obj1, obj2) {
var result = {};
for (var i in obj1) {
if (!obj2.hasOwnProperty(i)) {
result[i] = obj1[i];
}
}
return result;
};
var compareConfigs = compareJSON(shepherd.appConfig, JSON.parse(localAppConfig));
if (Object.keys(compareConfigs).length) {
var newConfig = Object.assign(JSON.parse(localAppConfig), compareConfigs);
console.log('config diff is found, updating local config');
console.log('config diff:');
console.log(compareConfigs);
shepherd.saveLocalAppConf(newConfig);
return newConfig;
} else {
return JSON.parse(localAppConfig);
}
} else {
console.log('local config file is not found!');
shepherd.saveLocalAppConf(shepherd.appConfig);
return shepherd.appConfig;
}
};
shepherd.readDebugLog = function() {
console.log('reading debug.log');
console.log(komodoDir + '/debug.log');
readLastLines
.read(komodoDir + '/debug.log', 50)
.then((lines) => console.log(lines));
};
function herder(flock, data) { function herder(flock, data) {
//console.log(flock); //console.log(flock);
//console.log(data); //console.log(data);
@ -149,7 +216,7 @@ function herder(flock, data) {
console.log('selected data: ' + data); console.log('selected data: ' + data);
//Make sure iguana isn't running before starting new process, kill it dammit! //Make sure iguana isn't running before starting new process, kill it dammit!
// A simple pid lookup // A simple pid lookup
/*ps.lookup({ /*ps.lookup({
command: 'iguana', command: 'iguana',
//arguments: '--debug', //arguments: '--debug',
@ -161,7 +228,7 @@ function herder(flock, data) {
if( process ){ if( process ){
console.log( 'PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments ); console.log( 'PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments );
console.log(process.pid); console.log(process.pid);
// A simple pid lookup // A simple pid lookup
ps.kill( process.pid, function( err ) { ps.kill( process.pid, function( err ) {
if (err) { if (err) {
throw new Error( err ); throw new Error( err );
@ -190,7 +257,7 @@ function herder(flock, data) {
fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) { fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) {
if (err) if (err)
return console.error(err); return console.error(err);
console.log('confs files copied successfully at: ' + iguanaConfsDir); console.log('confs files copied successfully at: ' + iguanaConfsDir);
}); });
@ -208,7 +275,7 @@ function herder(flock, data) {
}, function(err, apps) { }, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2 pm2.disconnect(); // Disconnect from PM2
if (err) if (err)
throw err throw err;
}); });
}); });
} }
@ -255,7 +322,8 @@ function herder(flock, data) {
cwd: iguanaDir, cwd: iguanaDir,
}, function(err, apps) { }, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2 pm2.disconnect(); // Disconnect from PM2
if (err) throw err if (err)
throw err;
}); });
}); });
} }
@ -271,6 +339,49 @@ function slayer(flock) {
}); });
} }
shepherd.saveLocalAppConf = function(appSettings) {
var appConfFileName = iguanaDir + '/config.json';
var FixFilePermissions = function() {
return new Promise(function(resolve, reject) {
var result = 'config.json file permissions updated to Read/Write';
fsnode.chmodSync(appConfFileName, '0666');
setTimeout(function() {
console.log(result);
resolve(result);
}, 1000);
});
}
var FsWrite = function() {
return new Promise(function(resolve, reject) {
var result = 'config.json write file is done'
fs.writeFile(appConfFileName,
JSON.stringify(appSettings)
.replace(/,/g, ',\n') // format json in human readable form
.replace(/:/g, ': ')
.replace(/{/g, '{\n')
.replace(/}/g, '\n}'), 'utf8', function(err) {
if (err)
return console.log(err);
});
fsnode.chmodSync(appConfFileName, '0666');
setTimeout(function() {
console.log(result);
console.log('app conf.json file is created successfully at: ' + iguanaConfsDir);
resolve(result);
}, 2000);
});
}
FsWrite()
.then(FixFilePermissions()); // not really required now
}
function setConf(flock) { function setConf(flock) {
console.log(flock); console.log(flock);
@ -303,7 +414,7 @@ function setConf(flock) {
fs.ensureFile(DaemonConfPath, function(err) { fs.ensureFile(DaemonConfPath, function(err) {
console.log(err); // => null console.log(err); // => null
}) });
setTimeout(function() { setTimeout(function() {
console.log(result); console.log(result);
@ -335,7 +446,7 @@ function setConf(flock) {
} }
var rmlines = data.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, '\n'); var rmlines = data.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, '\n');
fs.writeFile(DaemonConfPath, rmlines, 'utf8', function(err) { fs.writeFile(DaemonConfPath, rmlines, 'utf8', function(err) {
if (err) if (err)
return console.log(err); return console.log(err);
@ -430,7 +541,7 @@ function setConf(flock) {
console.log('addnode: OK'); console.log('addnode: OK');
} else { } else {
console.log('addnode: NOT FOUND') console.log('addnode: NOT FOUND')
fs.appendFile(DaemonConfPath, fs.appendFile(DaemonConfPath,
'\naddnode=78.47.196.146' + '\naddnode=78.47.196.146' +
'\naddnode=5.9.102.210' + '\naddnode=5.9.102.210' +
'\naddnode=178.63.69.164' + '\naddnode=178.63.69.164' +

Loading…
Cancel
Save