From e11869d641ba3fa6a8aedec07f3658f5b34748b7 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Wed, 23 Aug 2017 18:48:02 +0300 Subject: [PATCH] kill rogue komodo-cli during clean exit --- main.js | 41 ++--------------------------------------- routes/shepherd.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/main.js b/main.js index 7912a5b..2cdbaee 100644 --- a/main.js +++ b/main.js @@ -75,45 +75,8 @@ shepherd.writeLog(`app started in ${(appConfig.dev ? 'dev mode' : ' user mode')} shepherd.setConfKMD(); -// kill rogue iguana copies on start if (appConfig.killIguanaOnStart) { - let iguanaGrep; - - switch (osPlatform) { - case 'darwin': - iguanaGrep = "ps -p $(ps -A | grep -m1 iguana | awk '{print $1}') | grep -i iguana"; - break; - case 'linux': - iguanaGrep = 'ps -p $(pidof iguana) | grep -i iguana'; - break; - case 'win32': - iguanaGrep = 'tasklist'; - break; - } - - exec(iguanaGrep, function(error, stdout, stderr) { - if (stdout.indexOf('iguana') > -1) { - const pkillCmd = osPlatform === 'win32' ? 'taskkill /f /im iguana.exe' : 'pkill -15 iguana'; - - console.log('found another iguana process(es)'); - shepherd.writeLog('found another iguana process(es)'); - - exec(pkillCmd, function(error, stdout, stderr) { - console.log(`${pkillCmd} is issued`); - shepherd.writeLog(`${pkillCmd} is issued`); - - if (error !== null) { - console.log(`${pkillCmd} exec error: ${error}`); - shepherd.writeLog(`${pkillCmd} exec error: ${error}`); - }; - }); - } - - if (error !== null) { - console.log(`${iguanaGrep} exec error: ${error}`); - shepherd.writeLog(`${iguanaGrep} exec error: ${error}`); - }; - }); + shepherd.killRogueProcess('iguana'); } guiapp.use(function(req, res, next) { @@ -423,7 +386,7 @@ function createWindow(status) { shepherd.writeLog(result); resolve(result); - }, 2000) + }, 2000); }) } diff --git a/routes/shepherd.js b/routes/shepherd.js index 2c293c2..28b77d0 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -92,6 +92,48 @@ shepherd.defaultAppConfig = Object.assign({}, shepherd.appConfig); shepherd.coindInstanceRegistry = coindInstanceRegistry; +shepherd.killRogueProcess = function(processName) { + // kill rogue process copies on start + let processGrep; + const osPlatform = os.platform(); + + switch (osPlatform) { + case 'darwin': + processGrep = "ps -p $(ps -A | grep -m1 " + processName + " | awk '{print $1}') | grep -i " + processName; + break; + case 'linux': + processGrep = 'ps -p $(pidof ' + processName + ') | grep -i ' + processName; + break; + case 'win32': + processGrep = 'tasklist'; + break; + } + + exec(processGrep, function(error, stdout, stderr) { + if (stdout.indexOf(processName) > -1) { + const pkillCmd = osPlatform === 'win32' ? 'taskkill /f /im ' + processName + '.exe' : 'pkill -15 ' + processName; + + console.log('found another ' + processName + ' process(es)'); + shepherd.writeLog('found another ' + processName + ' process(es)'); + + exec(pkillCmd, function(error, stdout, stderr) { + console.log(`${pkillCmd} is issued`); + shepherd.writeLog(`${pkillCmd} is issued`); + + if (error !== null) { + console.log(`${pkillCmd} exec error: ${error}`); + shepherd.writeLog(`${pkillCmd} exec error: ${error}`); + }; + }); + } + + if (error !== null) { + console.log(`${processGrep} exec error: ${error}`); + shepherd.writeLog(`${processGrep} exec error: ${error}`); + }; + }); +} + shepherd.zcashParamsExist = function() { if (fs.existsSync(zcashParamsDir) && fs.existsSync(`${zcashParamsDir}/sprout-proving.key`) && @@ -819,6 +861,7 @@ shepherd.quitKomodod = function(timeout = 100) { const chain = key !== 'komodod' ? key : null; coindExitInterval[key] = setInterval(function() { + shepherd.killRogueProcess('komodo-cli'); console.log('exec ' + komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop'); exec(komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop', function(error, stdout, stderr) { console.log(`stdout: ${stdout}`); @@ -938,6 +981,7 @@ shepherd.post('/cli', function(req, res, next) { } }); } else { + shepherd.killRogueProcess('komodo-cli'); exec(komodocliBin + (_chain ? ' -ac_name=' + _chain : '') + ' ' + _cmd + _params, function(error, stdout, stderr) { console.log(`stdout: ${stdout}`); console.log(`stderr: ${stderr}`);