Browse Source

remove pm2

v0.25
pbca26 7 years ago
parent
commit
d3b6b458c8
  1. 74
      main.js
  2. 92
      routes/shepherd.js

74
main.js

@ -1,4 +1,4 @@
// main proc for EasyDEX GUI
// main proc for Agama
// this app spawns iguana in background in nontech-mode
const electron = require('electron'),
@ -7,9 +7,7 @@ const electron = require('electron'),
path = require('path'),
url = require('url'),
os = require('os'),
md5 = require('md5'),
spawn = require('child_process').spawn,
exec = require('child_process').exec,
md5 = require('./routes/md5.js'),
{ Menu } = require('electron'),
portscanner = require('portscanner'),
osPlatform = os.platform(),
@ -20,11 +18,7 @@ var express = require('express'),
fs = require('fs'),
fsnode = require('fs'),
fs = require('fs-extra'),
mkdirp = require('mkdirp'),
pm2 = require('pm2'),
cluster = require('cluster'),
numCPUs = require('os').cpus().length,
ipc = require('electron').ipcMain;
numCPUs = require('os').cpus().length;
Promise = require('bluebird');
@ -56,7 +50,7 @@ app.setVersion(appBasicInfo.version);
shepherd.binFixRights();
shepherd.createAgamaDirs();
const appSessionHash = md5(Date.now());
const appSessionHash = md5(Date.now().toString());
shepherd.writeLog(`app init ${appSessionHash}`);
shepherd.writeLog(`app info: ${appBasicInfo.name} ${appBasicInfo.version}`);
@ -69,6 +63,17 @@ shepherd.writeLog(`platform: ${osPlatform}`);
shepherd.writeLog(`os_release: ${os.release()}`);
shepherd.writeLog(`os_type: ${os.type()}`);
shepherd.log(`app init ${appSessionHash}`);
shepherd.log(`app info: ${appBasicInfo.name} ${appBasicInfo.version}`);
shepherd.log('sys info:');
shepherd.log(`totalmem_readable: ${formatBytes(os.totalmem())}`);
shepherd.log(`arch: ${os.arch()}`);
shepherd.log(`cpu: ${os.cpus()[0].model}`);
shepherd.log(`cpu_cores: ${os.cpus().length}`);
shepherd.log(`platform: ${osPlatform}`);
shepherd.log(`os_release: ${os.release()}`);
shepherd.log(`os_type: ${os.type()}`);
var appConfig = shepherd.loadLocalConfig(); // load app config
appConfig['daemonOutput'] = false; // shadow setting
@ -76,6 +81,7 @@ let __defaultAppSettings = require('./routes/appConfig.js').config;
__defaultAppSettings['daemonOutput'] = false; // shadow setting
const _defaultAppSettings = __defaultAppSettings;
shepherd.log(`app started in ${(appConfig.dev ? 'dev mode' : ' user mode')}`);
shepherd.writeLog(`app started in ${(appConfig.dev ? 'dev mode' : ' user mode')}`);
shepherd.setConfKMD();
@ -403,24 +409,15 @@ function createWindow(status) {
// DEVTOOLS - only for dev purposes - ca333
// mainWindow.webContents.openDevTools()
function pm2Exit() {
const ConnectToPm2 = function() {
function appExit() {
const CloseDaemons = function() {
return new Promise(function(resolve, reject) {
shepherd.log('Closing Main Window...');
shepherd.writeLog('exiting app...');
shepherd.quitKomodod(1000);
pm2.connect(true, function(err) {
shepherd.log('connecting to pm2...');
shepherd.writeLog('connecting to pm2...');
if (err) {
shepherd.log(err);
}
});
const result = 'Connecting To Pm2: done';
const result = 'Closing daemons: done';
shepherd.log(result);
shepherd.writeLog(result);
@ -428,31 +425,6 @@ function createWindow(status) {
})
}
const KillPm2 = function() {
return new Promise(function(resolve, reject) {
shepherd.log('killing to pm2...');
shepherd.writeLog('killing to pm2...');
pm2.killDaemon(function(err) {
pm2.disconnect();
shepherd.log('killed to pm2...');
shepherd.writeLog('killed to pm2...');
if (err)
throw err;
});
const result = 'Killing Pm2: done';
setTimeout(function() {
shepherd.log(result);
shepherd.writeLog(result);
resolve(result);
}, 2000);
})
}
const HideMainWindow = function() {
return new Promise(function(resolve, reject) {
const result = 'Hiding Main Window: done';
@ -475,7 +447,6 @@ function createWindow(status) {
return new Promise(function(resolve, reject) {
const result = 'Quiting App: done';
KillPm2(); // required for normal app quit in iguana-less mode
app.quit();
shepherd.log(result);
resolve(result);
@ -483,10 +454,7 @@ function createWindow(status) {
}
const closeApp = function() {
ConnectToPm2()
.then(function(result) {
return KillPm2();
})
CloseDaemons()
.then(HideMainWindow)
.then(HideAppClosingWindow)
.then(QuitApp);
@ -509,7 +477,7 @@ function createWindow(status) {
// if window closed we kill iguana proc
mainWindow.on('closed', function() {
pm2Exit();
appExit();
});
}
}

92
routes/shepherd.js

@ -7,15 +7,12 @@ const electron = require('electron'),
fsnode = require('fs'),
fs = require('fs-extra'),
_fs = require('graceful-fs'),
mkdirp = require('mkdirp'),
express = require('express'),
exec = require('child_process').exec,
spawn = require('child_process').spawn,
md5 = require('md5'),
pm2 = require('pm2'),
md5 = require('./md5.js'),
request = require('request'),
async = require('async'),
rimraf = require('rimraf'),
portscanner = require('portscanner'),
aes256 = require('nodejs-aes256'),
AdmZip = require('adm-zip'),
@ -88,7 +85,8 @@ shepherd.getAppRuntimeLog = function() {
};
shepherd.log = function(msg) {
if (shepherd.appConfig.dev) {
if (shepherd.appConfig.dev ||
shepherd.appConfig.debug) {
console.log(msg);
}
@ -562,7 +560,7 @@ shepherd.testBins = function(daemonName) {
}
});
pm2.connect(true,function(err) { //start up pm2 god
/*pm2.connect(true,function(err) { //start up pm2 god
if (err) {
shepherd.error(err);
process.exit(2);
@ -598,7 +596,7 @@ shepherd.testBins = function(daemonName) {
// throw err;
}
});
});
});*/
setTimeout(function() {
const options = {
@ -2031,58 +2029,6 @@ shepherd.post('/herd', function(req, res) {
}
});
/*
* type: POST
* params: herdname
*/
shepherd.post('/herdlist', function(req, res) {
shepherd.log(req.body.herdname);
pm2.connect(true, function(err) {
if (err) {
shepherd.writeLog(`herdlist err: ${err}`);
shepherd.log(`herdlist err:: ${err}`);
}
pm2.describe(req.body.herdname, function(err, list) {
pm2.disconnect(); // disconnect after getting proc info list
if (err) {
shepherd.writeLog(`pm2.describe err: ${err}`);
shepherd.log(`pm2.describe err: ${err}`);
}
shepherd.log(list[0].pm2_env.status) // print status of IGUANA proc
shepherd.log(list[0].pid) // print pid of IGUANA proc
shepherd.writeLog(list[0].pm2_env.status);
shepherd.writeLog(list[0].pid);
const obj = {
herdname: req.body.herdname,
status: list[0].pm2_env.status,
pid: list[0].pid,
};
res.end(JSON.stringify(obj));
});
});
});
/*
* type: POST
*/
shepherd.post('/slay', function(req, res) {
shepherd.log('======= req.body =======');
shepherd.log(req.body);
slayer(req.body.slay);
const obj = {
msg: 'success',
result: 'result',
};
res.end(JSON.stringify(obj));
});
/*
* type: POST
*/
@ -2092,7 +2038,6 @@ shepherd.post('/setconf', function(req, res) {
if (os.platform() === 'win32' &&
req.body.chain == 'komodod') {
setkomodoconf = spawn(path.join(__dirname, '../build/artifacts.supernet.org/latest/windows/genkmdconf.bat'));
setkomodoconf = spawn(path.join(__dirname, '../assets/bin/win64/genkmdconf.bat'));
} else {
setConf(req.body.chain);
@ -2239,12 +2184,12 @@ shepherd.get('/kick', function(req, res, next) {
shepherd.log('deleting ' + currentKickItem.type + (currentKickItem.match ? ' ' + currentKickItem.match : '') + ' ' + iguanaDir + '/' + currentKickItem.name.replace('[coin]', _coin));
if (currentKickItem.type === 'folder' ||
currentKickItem.type === 'file') {
rimraf(`${iguanaDir}/${currentKickItem.name.replace('[coin]', _coin)}`, function(err) {
/*rimraf(`${iguanaDir}/${currentKickItem.name.replace('[coin]', _coin)}`, function(err) {
if (err) {
shepherd.writeLog(`kickstart err: ${err}`);
shepherd.log(`kickstart err: ${err}`);
}
});
});*/
} else if (currentKickItem.type === 'pattern') {
let dirItems = fs.readdirSync(`${iguanaDir}/currentKickItem.name.replace('[coin]', _coin)`);
@ -2252,12 +2197,12 @@ shepherd.get('/kick', function(req, res, next) {
dirItems.length) {
for (let j = 0; j < dirItems.length; j++) {
if (dirItems[j].indexOf(currentKickItem.match) > -1) {
rimraf(`${iguanaDir}/${currentKickItem.name.replace('[coin]', _coin)}/${dirItems[j]}`, function(err) {
/*rimraf(`${iguanaDir}/${currentKickItem.name.replace('[coin]', _coin)}/${dirItems[j]}`, function(err) {
if (err) {
shepherd.writeLog(`kickstart err: ${err}`);
shepherd.log(`kickstart err: ${err}`);
}
});
});*/
shepherd.log(`deleting ${dirItems[j]}`);
}
@ -2424,7 +2369,7 @@ function herder(flock, data) {
}
}
if (flock === 'zcashd') {
if (flock === 'zcashd') { // TODO: fix(?)
let kmdDebugLogLocation = `${zcashDir}/debug.log`;
shepherd.log('zcashd flock selected...');
@ -2432,7 +2377,7 @@ function herder(flock, data) {
shepherd.writeLog('zcashd flock selected...');
shepherd.writeLog(`selected data: ${data}`);
pm2.connect(true, function(err) { // start up pm2 god
/*pm2.connect(true, function(err) { // start up pm2 god
if (err) {
shepherd.error(err);
process.exit(2);
@ -2454,22 +2399,10 @@ function herder(flock, data) {
}
// throw err;
});
});
});*/
}
}
function slayer(flock) {
shepherd.log(flock);
pm2.delete(flock, function(err, ret) {
pm2.disconnect();
shepherd.writeLog(`deleting flock ${flock}`);
shepherd.writeLog(ret);
shepherd.log(ret);
});
}
shepherd.setConfKMD = function() {
let komodoDir;
let zcashDir;
@ -2802,7 +2735,6 @@ function setConf(flock) {
})
.then(RemoveLines)
.then(CheckConf);
// .then(MakeConfReadOnly);
}
function getConf(flock) {

Loading…
Cancel
Save