Browse Source

Merge pull request #97 from pbca26/master

komodod quit
all-modes
pbca26 8 years ago
committed by GitHub
parent
commit
9a6afe580d
  1. 16
      main.js
  2. 61
      routes/shepherd.js

16
main.js

@ -70,7 +70,7 @@ if (appConfig.killIguanaOnStart) {
} }
guiapp.use(function(req, res, next) { guiapp.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', appConfig.dev ? '*' : 'http://127.0.0.1:' + appConfig.iguanaAppPort); res.header('Access-Control-Allow-Origin', appConfig.dev ? '*' : 'http://127.0.0.1:3000');
res.header('Access-Control-Allow-Headers', 'X-Requested-With'); res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.header('Access-Control-Allow-Credentials', 'true'); res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Headers', 'Content-Type'); res.header('Access-Control-Allow-Headers', 'Content-Type');
@ -121,7 +121,7 @@ server.listen(appConfig.iguanaAppPort, function() {
console.log('guiapp and sockets.io are listening on port ' + appConfig.iguanaAppPort + '!'); console.log('guiapp and sockets.io are listening on port ' + appConfig.iguanaAppPort + '!');
}); });
io.set('origins', 'http://127.0.0.1:' + appConfig.iguanaAppPort); // set origin io.set('origins', appConfig.dev ? 'http://127.0.0.1:3000' : 'http://127.0.0.1:' + appConfig.iguanaAppPort); // set origin
io.on('connection', function(client) { io.on('connection', function(client) {
console.log('EDEX GUI is connected...'); console.log('EDEX GUI is connected...');
@ -327,7 +327,11 @@ 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://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/EasyDEX-GUI/'); if (appConfig.v2) {
mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/EasyDEX-GUI/react/build');
} else {
mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/EasyDEX-GUI/');
}
} else { } else {
mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/main.html'); mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/main.html');
} }
@ -350,6 +354,12 @@ 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...');
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...');

61
routes/shepherd.js

@ -90,9 +90,22 @@ shepherd.appConfig = {
"linux": 1000000 "linux": 1000000
}, },
"killIguanaOnStart": true, "killIguanaOnStart": true,
"dev": false "dev": false,
"v2": false
}; };
shepherd.quitKomodod = function() {
// exit komodod gracefully
console.log('exec ' + komodocliBin + ' stop');
exec(komodocliBin + ' stop', function(error, stdout, stderr) {
console.log('stdout: ' + stdout)
console.log('stderr: ' + stderr)
if (error !== null) {
console.log('exec error: ' + error)
}
});
}
shepherd.saveLocalAppConf = function(appSettings) { shepherd.saveLocalAppConf = function(appSettings) {
var appConfFileName = iguanaDir + '/config.json'; var appConfFileName = iguanaDir + '/config.json';
@ -737,24 +750,36 @@ function herder(flock, data) {
portscanner.checkPortStatus(_port, '127.0.0.1', function(error, status) { portscanner.checkPortStatus(_port, '127.0.0.1', function(error, status) {
// 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') {
pm2.connect(true, function(err) { // start up pm2 god // start komodod via exec
if (err) { if (data.ac_name === 'komodod') {
console.error(err); console.log('exec' + komododBin + ' ' + data.ac_options.join(' '));
process.exit(2); exec(komododBin + ' ' + data.ac_options.join(' '), function(error, stdout, stderr) {
} console.log('stdout: ' + stdout)
console.log('stderr: ' + stderr)
pm2.start({ if (error !== null) {
script: komododBin, // path to binary console.log('exec error: ' + error)
name: data.ac_name, // REVS, USD, EUR etc. }
exec_mode : 'fork',
cwd: komodoDir,
args: data.ac_options
}, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2
if (err)
throw err;
}); });
}); } else {
pm2.connect(true, function(err) { // start up pm2 god
if (err) {
console.error(err);
process.exit(2);
}
pm2.start({
script: komododBin, // path to binary
name: data.ac_name, // REVS, USD, EUR etc.
exec_mode : 'fork',
cwd: komodoDir,
args: data.ac_options
}, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2
if (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');
} }

Loading…
Cancel
Save