Browse Source

native daemon detached mode

v0.25
pbca26 7 years ago
parent
commit
eb8d9a3c5e
  1. 16
      routes/appConfig.js
  2. 50
      routes/shepherd/daemonControl.js
  3. 1
      routes/shepherd/dashboardUpdate.js
  4. 110
      routes/shepherd/quitDaemon.js

16
routes/appConfig.js

@ -15,6 +15,9 @@ const appConfig = {
walletUnlockTimeout: 3600, walletUnlockTimeout: 3600,
}, },
cliStopTimeout: 1000, cliStopTimeout: 1000,
disableKomododDownModal: false,
failedRPCAttemptsThreshold: 10,
stopNativeDaemonsOnQuit: true,
}, },
schema: { schema: {
host: { host: {
@ -95,6 +98,19 @@ const appConfig = {
cliStopTimeout: { cliStopTimeout: {
display: true, display: true,
displayName: 'CLI stop timeout', displayName: 'CLI stop timeout',
info: 'Timeout between consequent CLI stop commands',
type: 'number',
},
stopNativeDaemonsOnQuit: {
display: true,
displayName: 'Stop native daemons on app quit',
info: 'If set to false agama will run in detached coin daemon mode',
type: 'boolean',
},
failedRPCAttemptsThreshold: {
display: true,
displayName: 'Failed RPC connect attempts threshold',
info: 'Number of allowed consequent RPC connect failures before the app marks native coin daemon as not running properly',
type: 'number', type: 'number',
}, },
}, },

50
routes/shepherd/daemonControl.js

@ -1,3 +1,5 @@
const spawn = require('child_process').spawn;
module.exports = (shepherd) => { module.exports = (shepherd) => {
const getConf = (flock, coind) => { const getConf = (flock, coind) => {
let DaemonConfPath = ''; let DaemonConfPath = '';
@ -135,7 +137,8 @@ module.exports = (shepherd) => {
// check if komodod instance is already running // check if komodod instance is already running
shepherd.portscanner.checkPortStatus(_port, '127.0.0.1', (error, status) => { shepherd.portscanner.checkPortStatus(_port, '127.0.0.1', (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' ||
!shepherd.appConfig.stopNativeDaemonsOnQuit) {
// start komodod via exec // start komodod via exec
const _customParamDict = { const _customParamDict = {
silent: '&', silent: '&',
@ -169,25 +172,33 @@ module.exports = (shepherd) => {
if (!shepherd.kmdMainPassiveMode) { if (!shepherd.kmdMainPassiveMode) {
let _arg = `${coindACParam}${data.ac_options.join(' ')}${_customParam}`; let _arg = `${coindACParam}${data.ac_options.join(' ')}${_customParam}`;
_arg = _arg.trim().split(' '); _arg = _arg.trim().split(' ');
shepherd.execFile(`${shepherd.komododBin}`, _arg, {
maxBuffer: 1024 * 1000000 // 1000 mb
}, (error, stdout, stderr) => {
shepherd.writeLog(`stdout: ${stdout}`);
shepherd.writeLog(`stderr: ${stderr}`);
if (error !== null) { if (!shepherd.appConfig.stopNativeDaemonsOnQuit) {
shepherd.log(`exec error: ${error}`); spawn(shepherd.komododBin, _arg, {
shepherd.writeLog(`exec error: ${error}`); stdio: 'ignore', // piping all stdio to /dev/null
detached: true,
if (error.toString().indexOf('using -reindex') > -1) { }).unref();
shepherd.io.emit('service', { } else {
komodod: { shepherd.execFile(`${shepherd.komododBin}`, _arg, {
error: 'run -reindex', maxBuffer: 1024 * 1000000 // 1000 mb
}, }, (error, stdout, stderr) => {
}); shepherd.writeLog(`stdout: ${stdout}`);
shepherd.writeLog(`stderr: ${stderr}`);
if (error !== null) {
shepherd.log(`exec error: ${error}`);
shepherd.writeLog(`exec error: ${error}`);
if (error.toString().indexOf('using -reindex') > -1) {
shepherd.io.emit('service', {
komodod: {
error: 'run -reindex',
},
});
}
} }
} });
}); }
} }
} else { } else {
if (shepherd.kmdMainPassiveMode) { if (shepherd.kmdMainPassiveMode) {
@ -731,7 +742,8 @@ module.exports = (shepherd) => {
shepherd.portscanner.checkPortStatus(_port, '127.0.0.1', (error, status) => { shepherd.portscanner.checkPortStatus(_port, '127.0.0.1', (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 === 'open') { if (status === 'open' &&
shepherd.appConfig.stopNativeDaemonsOnQuit) {
if (!skipError) { if (!skipError) {
shepherd.log(`komodod service start error at port ${_port}, reason: port is closed`); shepherd.log(`komodod service start error at port ${_port}, reason: port is closed`);
shepherd.writeLog(`komodod service start error at port ${_port}, reason: port is closed`); shepherd.writeLog(`komodod service start error at port ${_port}, reason: port is closed`);

1
routes/shepherd/dashboardUpdate.js

@ -269,6 +269,7 @@ module.exports = (shepherd) => {
0 0
]; ];
} }
return new shepherd.Promise((resolve, reject) => { return new shepherd.Promise((resolve, reject) => {
_bitcoinRPC( _bitcoinRPC(
_coin, _coin,

110
routes/shepherd/quitDaemon.js

@ -6,70 +6,74 @@ module.exports = (shepherd) => {
shepherd.lockDownAddCoin = true; shepherd.lockDownAddCoin = true;
for (let key in shepherd.coindInstanceRegistry) { for (let key in shepherd.coindInstanceRegistry) {
const chain = key !== 'komodod' ? key : null; if (shepherd.appConfig.stopNativeDaemonsOnQuit) {
let _coindQuitCmd = shepherd.komodocliBin; const chain = key !== 'komodod' ? key : null;
let _coindQuitCmd = shepherd.komodocliBin;
// any coind // any coind
if (shepherd.nativeCoindList[key.toLowerCase()]) { if (shepherd.nativeCoindList[key.toLowerCase()]) {
_coindQuitCmd = `${shepherd.coindRootDir}/${key.toLowerCase()}/${shepherd.nativeCoindList[key.toLowerCase()].bin.toLowerCase()}-cli`; _coindQuitCmd = `${shepherd.coindRootDir}/${key.toLowerCase()}/${shepherd.nativeCoindList[key.toLowerCase()].bin.toLowerCase()}-cli`;
} }
if (key === 'CHIPS') { if (key === 'CHIPS') {
_coindQuitCmd = shepherd.chipscliBin; _coindQuitCmd = shepherd.chipscliBin;
} }
const execCliStop = () => { const execCliStop = () => {
let _arg = []; let _arg = [];
if (chain && if (chain &&
!shepherd.nativeCoindList[key.toLowerCase()] && key !== 'CHIPS') { !shepherd.nativeCoindList[key.toLowerCase()] && key !== 'CHIPS') {
_arg.push(`-ac_name=${chain}`); _arg.push(`-ac_name=${chain}`);
if (shepherd.appConfig.dataDir.length) { if (shepherd.appConfig.dataDir.length) {
_arg.push(`-datadir=${shepherd.appConfig.dataDir + (key !== 'komodod' ? '/' + key : '')}`); _arg.push(`-datadir=${shepherd.appConfig.dataDir + (key !== 'komodod' ? '/' + key : '')}`);
}
} else if (key === 'komodod' && shepherd.appConfig.dataDir.length) {
_arg.push(`-datadir=${shepherd.appConfig.dataDir}`);
} }
} else if (key === 'komodod' && shepherd.appConfig.dataDir.length) {
_arg.push(`-datadir=${shepherd.appConfig.dataDir}`);
}
_arg.push('stop'); _arg.push('stop');
shepherd.execFile(`${_coindQuitCmd}`, _arg, (error, stdout, stderr) => { shepherd.execFile(`${_coindQuitCmd}`, _arg, (error, stdout, stderr) => {
shepherd.log(`stdout: ${stdout}`); shepherd.log(`stdout: ${stdout}`);
shepherd.log(`stderr: ${stderr}`); shepherd.log(`stderr: ${stderr}`);
if (stdout.indexOf('EOF reached') > -1 || if (stdout.indexOf('EOF reached') > -1 ||
stderr.indexOf('EOF reached') > -1 || stderr.indexOf('EOF reached') > -1 ||
(error && error.toString().indexOf('Command failed') > -1 && !stderr) || // win "special snowflake" case (error && error.toString().indexOf('Command failed') > -1 && !stderr) || // win "special snowflake" case
stdout.indexOf('connect to server: unknown (code -1)') > -1 || stdout.indexOf('connect to server: unknown (code -1)') > -1 ||
stderr.indexOf('connect to server: unknown (code -1)') > -1) { stderr.indexOf('connect to server: unknown (code -1)') > -1) {
delete shepherd.coindInstanceRegistry[key]; delete shepherd.coindInstanceRegistry[key];
clearInterval(coindExitInterval[key]); clearInterval(coindExitInterval[key]);
} }
// workaround for AGT-65 // workaround for AGT-65
const _port = shepherd.assetChainPorts[key]; const _port = shepherd.assetChainPorts[key];
setTimeout(() => { setTimeout(() => {
shepherd.portscanner.checkPortStatus(_port, '127.0.0.1', (error, status) => { shepherd.portscanner.checkPortStatus(_port, '127.0.0.1', (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') {
delete shepherd.coindInstanceRegistry[key]; delete shepherd.coindInstanceRegistry[key];
clearInterval(coindExitInterval[key]); clearInterval(coindExitInterval[key]);
} }
}); });
}, 100); }, 100);
if (error !== null) { if (error !== null) {
shepherd.log(`exec error: ${error}`); shepherd.log(`exec error: ${error}`);
} }
setTimeout(() => { setTimeout(() => {
shepherd.killRogueProcess(key === 'CHIPS' ? 'chips-cli' : 'komodo-cli'); shepherd.killRogueProcess(key === 'CHIPS' ? 'chips-cli' : 'komodo-cli');
}, 100); }, 100);
}); });
} }
execCliStop();
coindExitInterval[key] = setInterval(() => {
execCliStop(); execCliStop();
}, timeout); coindExitInterval[key] = setInterval(() => {
execCliStop();
}, timeout);
} else {
delete shepherd.coindInstanceRegistry[key];
}
} }
} }

Loading…
Cancel
Save