Browse Source

debug.log unlink fix

all-modes
pbca26 7 years ago
parent
commit
2f4c514de3
  1. 2
      routes/appConfig.js
  2. 96
      routes/shepherd.js

2
routes/appConfig.js

@ -160,7 +160,7 @@ const appConfig = {
}, },
daemonOutput: { daemonOutput: {
display: false, display: false,
initDisplay: true, initDisplay: false,
displayName: 'Output daemon prints (debug)', displayName: 'Output daemon prints (debug)',
info: 'Output daemon prints to GUI for debug purposes', info: 'Output daemon prints to GUI for debug purposes',
type: 'boolean', type: 'boolean',

96
routes/shepherd.js

@ -396,7 +396,7 @@ shepherd.post('/native/dashboard/update', function(req, res, next) {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ payload: _payload }), body: JSON.stringify({ payload: _payload }),
timeout: 5000, timeout: 10000,
}; };
request(options, function(error, response, body) { request(options, function(error, response, body) {
@ -482,7 +482,9 @@ shepherd.testBins = function(daemonName) {
try { try {
_fs.access(`${iguanaTestDir}/${daemonName}Test.log`, fs.constants.R_OK, function(err) { _fs.access(`${iguanaTestDir}/${daemonName}Test.log`, fs.constants.R_OK, function(err) {
if (!err) { if (!err) {
_fs.unlink(`${iguanaTestDir}/${daemonName}Test.log`); try {
_fs.unlink(`${iguanaTestDir}/${daemonName}Test.log`);
} catch (e) {}
} else { } else {
console.log(`path ${iguanaTestDir}/${daemonName}Test.log doesnt exist`); console.log(`path ${iguanaTestDir}/${daemonName}Test.log doesnt exist`);
} }
@ -2350,37 +2352,47 @@ shepherd.post('/herd', function(req, res) {
if (req.body.options && if (req.body.options &&
!req.body.options.manualStart) { !req.body.options.manualStart) {
function testCoindPort() { function testCoindPort(skipError) {
if (!lockDownAddCoin) { if (!lockDownAddCoin) {
const _port = assetChainPorts[req.body.options.ac_name]; const _port = assetChainPorts[req.body.options.ac_name];
portscanner.checkPortStatus(_port, '127.0.0.1', function(error, status) { portscanner.checkPortStatus(_port, '127.0.0.1', function(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') {
console.log(`komodod service start error at port ${_port}, reason: port is closed`); if (!skipError) {
shepherd.writeLog(`komodod service start error at port ${_port}, reason: port is closed`); console.log(`komodod service start error at port ${_port}, reason: port is closed`);
cache.io.emit('service', { shepherd.writeLog(`komodod service start error at port ${_port}, reason: port is closed`);
komodod: { cache.io.emit('service', {
error: `error starting ${req.body.herd} ${req.body.options.ac_name} daemon. Port ${_port} is already taken!`, komodod: {
}, error: `error starting ${req.body.herd} ${req.body.options.ac_name} daemon. Port ${_port} is already taken!`,
}); },
});
const obj = { const obj = {
msg: 'error', msg: 'error',
result: `error starting ${req.body.herd} ${req.body.options.ac_name} daemon. Port ${_port} is already taken!`, result: `error starting ${req.body.herd} ${req.body.options.ac_name} daemon. Port ${_port} is already taken!`,
}; };
res.status(500); res.status(500);
res.end(JSON.stringify(obj)); res.end(JSON.stringify(obj));
} else {
console.log(`komodod service start success at port ${_port}`);
shepherd.writeLog(`komodod service start success at port ${_port}`);
}
} else { } else {
herder(req.body.herd, req.body.options); if (!skipError) {
herder(req.body.herd, req.body.options);
const obj = { const obj = {
msg: 'success', msg: 'success',
result: 'result', result: 'result',
}; };
res.end(JSON.stringify(obj)); res.end(JSON.stringify(obj));
} else {
console.log(`komodod service start error at port ${_port}, reason: unknown`);
shepherd.writeLog(`komodod service start error at port ${_port}, reason: unknown`);
}
} }
}); });
} }
@ -2390,7 +2402,7 @@ shepherd.post('/herd', function(req, res) {
// check if komodod instance is already running // check if komodod instance is already running
testCoindPort(); testCoindPort();
setTimeout(function() { setTimeout(function() {
testCoindPort(); testCoindPort(true);
}, 10000); }, 10000);
} else { } else {
herder(req.body.herd, req.body.options); herder(req.body.herd, req.body.options);
@ -2790,20 +2802,20 @@ function herder(flock, data) {
// truncate debug.log // truncate debug.log
try { try {
_fs.access(kmdDebugLogLocation, fs.constants.R_OK, function(err) { const _confFileAccess = _fs.accessSync(kmdDebugLogLocation, fs.R_OK | fs.W_OK);
if (err) {
console.log(`error accessing ${kmdDebugLogLocation}`); if (_confFileAccess) {
shepherd.writeLog(`error accessing ${kmdDebugLogLocation}`); console.log(`error accessing ${kmdDebugLogLocation}`);
} else { shepherd.writeLog(`error accessing ${kmdDebugLogLocation}`);
try { } else {
fs.unlink(kmdDebugLogLocation); try {
console.log(`truncate ${kmdDebugLogLocation}`); fs.unlink(kmdDebugLogLocation);
shepherd.writeLog(`truncate ${kmdDebugLogLocation}`); console.log(`truncate ${kmdDebugLogLocation}`);
} catch (e) { shepherd.writeLog(`truncate ${kmdDebugLogLocation}`);
console.log('cant unlink debug.log'); } catch (e) {
} console.log('cant unlink debug.log');
} }
}); }
} catch(e) { } catch(e) {
console.log(`komodod debug.log access err: ${e}`); console.log(`komodod debug.log access err: ${e}`);
shepherd.writeLog(`komodod debug.log access err: ${e}`); shepherd.writeLog(`komodod debug.log access err: ${e}`);
@ -2956,8 +2968,16 @@ shepherd.setConfKMD = function() {
shepherd.writeLog(`creating komodo conf in ${komodoDir}/komodo.conf`); shepherd.writeLog(`creating komodo conf in ${komodoDir}/komodo.conf`);
setConf('komodod'); setConf('komodod');
} else { } else {
shepherd.writeLog('komodo conf exists'); const _komodoConfSize = fs.lstatSync(`${komodoDir}/komodo.conf`);
console.log('komodo conf exists');
if (_komodoConfSize.size === 0) {
console.log('creating komodo conf');
shepherd.writeLog(`creating komodo conf in ${komodoDir}/komodo.conf`);
setConf('komodod');
} else {
shepherd.writeLog('komodo conf exists');
console.log('komodo conf exists');
}
} }
}); });
} }

Loading…
Cancel
Save