Browse Source

kill rogue komodo-cli during clean exit

all-modes
pbca26 7 years ago
parent
commit
e11869d641
  1. 41
      main.js
  2. 44
      routes/shepherd.js

41
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);
})
}

44
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}`);

Loading…
Cancel
Save