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. 49
      main.js
  5. 3
      package.json
  6. 28
      pull-gui.sh
  7. 135
      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="jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
<script type="text/javascript">
const remote = require('electron').remote;
var window = remote.getCurrentWindow();
</script>>
</head>
<body style="overflow:hidden;">
<div style="text-align: center;">

3
gui/init.js

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

49
main.js

@ -3,25 +3,23 @@
const electron = require('electron'),
app = electron.app,
BrowserWindow = electron.BrowserWindow;
var express = require('express'),
bodyParser = require('body-parser');
const path = require('path'),
BrowserWindow = electron.BrowserWindow,
path = require('path'),
url = require('url'),
os = require('os'),
spawn = require('child_process').spawn,
exec = require('child_process').exec;
var fs = require('fs'),
exec = require('child_process').exec,
fixPath = require('fix-path');
var express = require('express'),
bodyParser = require('body-parser'),
fs = require('fs'),
fsnode = require('fs'),
fs = require('fs-extra'),
mkdirp = require('mkdirp'),
pm2 = require('pm2');
var iguanaAppPort = 17777;
Promise = require('bluebird');
var appConfig = JSON.parse(fs.readFileSync('config.json', 'utf8'));
app.setName('Iguana');
if (os.platform() === 'linux') {
@ -29,45 +27,47 @@ if (os.platform() === 'linux') {
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
const _setImmediate = setImmediate,
_clearImmediate = clearImmediate;
process.once('loaded', () => {
global.setImmediate = _setImmediate;
global.clearImmediate = _clearImmediate;
if (os.platform() === 'darwin') {
process.setFdLimit(90000);
process.setFdLimit(appConfig.maxDescriptors.darwin);
}
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.urlencoded({ extended: false })); // support encoded bodies
guiapp.get('/', function (req, res) {
res.send('Iguana app server');
})
});
var guipath = path.join(__dirname, '/gui');
guiapp.use('/gui', express.static(guipath));
guiapp.use('/shepherd', shepherd);
var rungui = guiapp.listen(iguanaAppPort, function () {
console.log('guiapp listening on port ' + iguanaAppPort + '!');
var rungui = guiapp.listen(appConfig.iguanaAppPort, function () {
console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!');
})
module.exports = guiapp;
// END GUI App Settings
//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
@ -138,7 +138,7 @@ function createLoadingWindow() {
});
// 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
//loadingWindow.webContents.openDevTools()
@ -171,7 +171,7 @@ function createLoadingWindow() {
//if (os.platform() !== 'win32') { ig.stderr.on( 'error: ', data => { console.log( `stderr: ${data}` ); }); }
}
app.on('ready', createLoadingWindow)
app.on('ready', createLoadingWindow);
function createWindow (status) {
if ( status === 'open') {
@ -187,9 +187,9 @@ function createWindow (status) {
// load our index.html (i.e. easyDEX GUI)
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 {
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
@ -223,6 +223,7 @@ function createWindow (status) {
pm2.killDaemon(function(err) {
pm2.disconnect();
console.log('killed to pm2...');
if (err)
throw err;
});

3
package.json

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

28
pull-gui.sh

@ -14,25 +14,23 @@ else
git clone https://github.com/SuperNETorg/EasyDEX-GUI.git
fi
if [ -d "Iguana-application" ]; then
cd Iguana-application
git checkout 0.3.1
git branch 0.3.1 --track origin/0.3.1
git pull
else
git clone https://github.com/SuperNETorg/Iguana-application.git -b 0.3.1
cd Iguana-application
git branch 0.3.1 --track origin/0.3.1
fi
#if [ -d "Iguana-application" ]; then
# cd Iguana-application
# git checkout 0.3.1
# git pull
#else
# git clone https://github.com/SuperNETorg/Iguana-application.git -b 0.3.1
# cd Iguana-application
#fi
bower install
npm install
gulp electron
#bower install
#npm install
#gulp electron
cd ../../
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"

135
routes/shepherd.js

@ -10,7 +10,8 @@ const electron = require('electron'),
express = require('express'),
exec = require('child_process').exec,
md5 = require('md5'),
pm2 = require('pm2');
pm2 = require('pm2'),
readLastLines = require('read-last-lines');
Promise = require('bluebird');
@ -56,18 +57,33 @@ if (os.platform() === 'win32') {
iguanaConfsDirSrc = path.normalize(iguanaConfsDirSrc);
}
console.log(iguanaDir);
console.log(iguanaBin);
shepherd.appConfig = {
"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
shepherd.get('/', function(req, res, next) {
res.send('Iguana app server')
})
res.send('Iguana app server');
});
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);
})
});
shepherd.post('/herd', function(req, res) {
console.log('======= req.body =======');
@ -93,7 +109,8 @@ shepherd.post('/herdlist', function(req, res) {
pm2.describe(req.body.herdname, function(err, 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].pid) // print pid of IGUANA proc
@ -130,11 +147,61 @@ shepherd.post('/getconf', function(req, res) {
//console.log(req.body.chain);
var confpath = getConf(req.body.chain);
console.log('got conf path is:')
console.log('got conf path is:');
console.log(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) {
//console.log(flock);
//console.log(data);
@ -208,7 +275,7 @@ function herder(flock, data) {
}, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2
if (err)
throw err
throw err;
});
});
}
@ -255,7 +322,8 @@ function herder(flock, data) {
cwd: iguanaDir,
}, function(err, apps) {
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) {
console.log(flock);
@ -303,7 +414,7 @@ function setConf(flock) {
fs.ensureFile(DaemonConfPath, function(err) {
console.log(err); // => null
})
});
setTimeout(function() {
console.log(result);

Loading…
Cancel
Save