procs[id].process.on('exit', function (code, signal) { states.setState(id + '.alive', {val: false, ack: true}); states.setState(id + '.connected', {val: false, ack: true}); if (signal) { logger.warn('controller instance ' + id + ' terminated due to ' + signal); } else if (code === null) { logger.error('controller instance ' + id + ' terminated abnormally'); } else { if ((procs[id] && procs[id].stopping) || isStopping || wakeUp) { logger.info('controller instance ' + id + ' terminated with code ' + code); delete procs[id].stopping; delete procs[id].process; if (isStopping) { for (var i in procs) { if (procs[i].process) { return; } } allInstancesStopped = true; } return; } else { logger.error('controller instance ' + id + ' terminated with code ' + code); } } delete procs[id].process; if (!wakeUp) { setTimeout(function (_id) { startInstance(_id); }, 30000, id); } });
router.put('/state', function(req,res){ var drawingid=req.body.drawingid; var state=req.body.state; drawings.setState(state,drawingid,function(success){ res.json(success); }); });
function waitForInstances() { if (!allInstancesStopped) { setTimeout(waitForInstances, 100); } else { states.setState('system.host.' + hostname + '.alive', {val: false, ack: true}, function () { logger.info('controller terminated'); process.exit(0); }); } }
procs[id].process.on('exit', function (code, signal) { states.setState(id + '.alive', {val: false, ack: true}); if (signal) { logger.warn('controller instance ' + id + ' terminated due to ' + signal); } else if (code === null) { logger.error('controller instance ' + id + ' terminated abnormally'); } else { if (code === 0 || code === '0') { logger.info('controller instance ' + id + ' terminated with code ' + code); return; } else { logger.error('controller instance ' + id + ' terminated with code ' + code); } } delete procs[id].process; });
function stop() { logger.debug('stop isStopping=' + isStopping + ' isDaemon=' + isDaemon + ' allInstancesStopped=' + allInstancesStopped); if (isStopping) { states.setState('system.host.' + hostname + '.alive', {val: false, ack: true}, function () { logger.info('controller force terminating'); process.exit(1); return; }); } else { isStopping = true; } if (isDaemon) { // send instances SIGTERM, only needed if running in backround (isDaemon) for (var id in procs) { stopInstance(id); } } function waitForInstances() { if (!allInstancesStopped) { setTimeout(waitForInstances, 100); } else { states.setState('system.host.' + hostname + '.alive', {val: false, ack: true}, function () { logger.info('controller terminated'); process.exit(0); }); } } waitForInstances(); // force after 10s setTimeout(function () { states.setState('system.host.' + hostname + '.alive', {val: false, ack: true}, function () { logger.info('controller force terminated after 10s'); process.exit(1); }); }, 10000); }
setTimeout(function () { states.setState('system.host.' + hostname + '.alive', {val: false, ack: true}, function () { logger.info('controller force terminated after 10s'); process.exit(1); }); }, 10000);
function reportStatus() { var id = 'system.host.' + hostname; states.setState(id + '.alive', {val: true, ack: true, expire: 30, from: id}); states.setState(id + '.load', {val: parseFloat(os.loadavg()[0].toFixed(2)), ack: true, from: id}); states.setState(id + '.mem', {val: parseFloat((100 * os.freemem() / os.totalmem()).toFixed(0)), ack: true, from: id}); }