Browse Source

native daemon detached mode

v0.25
pbca26 7 years ago
parent
commit
eb8d9a3c5e
  1. 16
      routes/appConfig.js
  2. 16
      routes/shepherd/daemonControl.js
  3. 1
      routes/shepherd/dashboardUpdate.js
  4. 4
      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',
}, },
}, },

16
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,6 +172,13 @@ 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(' ');
if (!shepherd.appConfig.stopNativeDaemonsOnQuit) {
spawn(shepherd.komododBin, _arg, {
stdio: 'ignore', // piping all stdio to /dev/null
detached: true,
}).unref();
} else {
shepherd.execFile(`${shepherd.komododBin}`, _arg, { shepherd.execFile(`${shepherd.komododBin}`, _arg, {
maxBuffer: 1024 * 1000000 // 1000 mb maxBuffer: 1024 * 1000000 // 1000 mb
}, (error, stdout, stderr) => { }, (error, stdout, stderr) => {
@ -189,6 +199,7 @@ module.exports = (shepherd) => {
} }
}); });
} }
}
} else { } else {
if (shepherd.kmdMainPassiveMode) { if (shepherd.kmdMainPassiveMode) {
shepherd.coindInstanceRegistry[data.ac_name] = true; shepherd.coindInstanceRegistry[data.ac_name] = true;
@ -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,

4
routes/shepherd/quitDaemon.js

@ -6,6 +6,7 @@ module.exports = (shepherd) => {
shepherd.lockDownAddCoin = true; shepherd.lockDownAddCoin = true;
for (let key in shepherd.coindInstanceRegistry) { for (let key in shepherd.coindInstanceRegistry) {
if (shepherd.appConfig.stopNativeDaemonsOnQuit) {
const chain = key !== 'komodod' ? key : null; const chain = key !== 'komodod' ? key : null;
let _coindQuitCmd = shepherd.komodocliBin; let _coindQuitCmd = shepherd.komodocliBin;
@ -70,6 +71,9 @@ module.exports = (shepherd) => {
coindExitInterval[key] = setInterval(() => { coindExitInterval[key] = setInterval(() => {
execCliStop(); execCliStop();
}, timeout); }, timeout);
} else {
delete shepherd.coindInstanceRegistry[key];
}
} }
} }

Loading…
Cancel
Save