model/persistence.js
function() {
        var that = this;

        // Save a screenshot.
        if ($$logging.get('screenshots').enabled) {
            var filename = $$logging.get('screenshots').filename.replace('{date}', moment().format('YYYYMMDDhhmmss'));
            logger.info('Saving screenshot to ' + filename);

            var winCmd = path.join(__dirname, '../tools', 'nircmd.exe');
            var winArgs = ['savescreenshotfull', filename];

            var macCmd = '/usr/sbin/screencapture';
            var macArgs = ['-x', '-t', 'jpg', '-C', filename];

            var cmd = process.platform === 'win32' ? winCmd : macCmd;
            var args = process.platform === 'win32' ? winArgs : macArgs;

            var screenshot = child_process.spawn(cmd, args);
            screenshot.on('close', function(code, signal) {
                logger.info('Screenshot saved, restarting.');
                restart();
            });
        } else {
            restart();
        }

        function restart() {
            var restartCount = that.get('restartCount');
            restartCount++;

            var logList = 'App went away: ' + restartCount + ' times\n\n';
            _.each($$logging.get('logCache'), function(log) {
                logList += log.time + ' ' + log.level + ': ' + log.msg + '\n';
            });
            logger.error(logList);

            that.trigger('crash');

            if (restartCount >= that.get('restartMachineAfter')) {
                logger.info('Already restarted app ' + that.get('restartMachineAfter') + ' times, rebooting machine.');
                that.restartMachine();
                return;
            }

            that.set('restartCount', restartCount);
            that._isStartingUp = false;
            that._isShuttingDown = false;
            that.restartApp();
        }
    }
function() {
        var that = this;

        // Save a screenshot.
        if ($$logging.get('screenshots').enabled) {
            var filename = $$logging.get('screenshots').filename.replace('{date}', moment().format('YYYYMMDDhhmmss'));
            logger.info('Saving screenshot to ' + filename);

            var winCmd = path.join(__dirname, '../tools', 'nircmd.exe');
            var winArgs = ['savescreenshotfull', filename];

            var macCmd = '/usr/sbin/screencapture';
            var macArgs = ['-x', '-t', 'jpg', '-C', filename];

            var cmd = process.platform === 'win32' ? winCmd : macCmd;
            var args = process.platform === 'win32' ? winArgs : macArgs;

            var screenshot = child_process.spawn(cmd, args);
            screenshot.on('close', function(code, signal) {
                logger.info('Screenshot saved, restarting.');
                restart();
            });
        } else {
            restart();
        }

        function restart() {
            var restartCount = that.get('restartCount');
            restartCount++;

            var logList = 'App went away: ' + restartCount + ' times\n\n';
            _.each($$logging.get('logCache'), function(log) {
                logList += log.time + ' ' + log.level + ': ' + log.msg + '\n';
            });
            logger.error(logList);

            that.trigger('crash');

            if (restartCount >= that.get('restartMachineAfter')) {
                logger.info('Already restarted app ' + that.get('restartMachineAfter') + ' times, rebooting machine.');
                that.restartMachine();
                return;
            }

            that.set('restartCount', restartCount);
            that._isStartingUp = false;
            that._isShuttingDown = false;
            that.restartApp();
        }
    }
function ( ) { var that = this ; // Save a screenshot. if ( $$logging . get ( 'screenshots' ) . enabled ) { var filename = $$logging . get ( 'screenshots' ) . filename . replace ( '{date}' , moment ( ) . format ( 'YYYYMMDDhhmmss' ) ) ; logger . info ( 'Saving screenshot to ' + filename ) ; var winCmd = path . join ( __dirname , '../tools' , 'nircmd.exe' ) ; var winArgs = [ 'savescreenshotfull' , filename ] ; var macCmd = '/usr/sbin/screencapture' ; var macArgs = [ '-x' , '-t' , 'jpg' , '-C' , filename ] ; var cmd = process . platform === 'win32' ? winCmd : macCmd ; var args = process . platform === 'win32' ? winArgs : macArgs ; var screenshot = child_process . spawn ( cmd , args ) ; screenshot . on ( 'close' , function ( code , signal ) { logger . info ( 'Screenshot saved, restarting.' ) ; restart ( ) ; } ) ; } else { restart ( ) ; } function restart ( ) { var restartCount = that . get ( 'restartCount' ) ; restartCount ++ ; var logList = 'App went away: ' + restartCount + ' times\n\n' ; _ . each ( $$logging . get ( 'logCache' ) , function ( log ) { logList += log . time + ' ' + log . level + ': ' + log . msg + '\n' ; } ) ; logger . error ( logList ) ; that . trigger ( 'crash' ) ; if ( restartCount >= that . get ( 'restartMachineAfter' ) ) { logger . info ( 'Already restarted app ' + that . get ( 'restartMachineAfter' ) + ' times, rebooting machine.' ) ; that . restartMachine ( ) ; return ; } that . set ( 'restartCount' , restartCount ) ; that . _isStartingUp = false ; that . _isShuttingDown = false ; that . restartApp ( ) ; } }
When a heartbeat hasn't been received for a while, restart the app or the whole machine.
When a heartbeat hasn t been received for a while restart the app or the whole machine .