lib/shutdownManager.js
function ShutdownManager (params) {
        // Set State
	var that = this;
	this.isShuttingDown = false;
	this.actionChain = [];
	this.finalActionChain = [];

	// Set Parameters
	this.logger = (params && params.hasOwnProperty("logger")) ? params.logger : null;
	this.loggingPrefix = (params && params.hasOwnProperty("loggingPrefix")) ?
		params.loggingPrefix : DEFAULT_LOGGING_PREFIX;

	// Add Process Handlers
	process.on('SIGINT', function() {
                if (!that.emit('preShutdown', 'SIGINT')) {
    		    that._log("Received SIGINT, Beginning Shutdown Process");
                }
		that._shutdown(128+2, params.timeout);
	});

	process.on('SIGTERM', function() {
                if (!that.emit('preShutdown', 'SIGTERM')) {
		    that._log("Received SIGTERM, Beginning Shutdown Process");
                }
		that._shutdown(128+15, params.timeout);
	});

	process.on('uncaughtException', function (err) {
                if (!that.emit('preShutdown', 'uncaughtException', err)) {
                    that._log('Uncaught Exception Received, Beginning Shutdown Process');
                    that._log('Exception: '+err);
                }
 	        that._shutdown(255, params.timeout);
	});

	process.on('exit', function() {
		// Just in case we are getting to exit without previous conditions being met
		// Not sure if this happens - will test.
		if(!that.isShuttingDown) {
                    that.emit('preShutdown', 'exit');
                    that._log("Application Exiting for Undefined Reason, Beginning Shutdown Process");
                    that._shutdown(null, params.timeout);
		}
	});
        EventEmitter.call(this);
}
function ShutdownManager (params) {
        // Set State
	var that = this;
	this.isShuttingDown = false;
	this.actionChain = [];
	this.finalActionChain = [];

	// Set Parameters
	this.logger = (params && params.hasOwnProperty("logger")) ? params.logger : null;
	this.loggingPrefix = (params && params.hasOwnProperty("loggingPrefix")) ?
		params.loggingPrefix : DEFAULT_LOGGING_PREFIX;

	// Add Process Handlers
	process.on('SIGINT', function() {
                if (!that.emit('preShutdown', 'SIGINT')) {
    		    that._log("Received SIGINT, Beginning Shutdown Process");
                }
		that._shutdown(128+2, params.timeout);
	});

	process.on('SIGTERM', function() {
                if (!that.emit('preShutdown', 'SIGTERM')) {
		    that._log("Received SIGTERM, Beginning Shutdown Process");
                }
		that._shutdown(128+15, params.timeout);
	});

	process.on('uncaughtException', function (err) {
                if (!that.emit('preShutdown', 'uncaughtException', err)) {
                    that._log('Uncaught Exception Received, Beginning Shutdown Process');
                    that._log('Exception: '+err);
                }
 	        that._shutdown(255, params.timeout);
	});

	process.on('exit', function() {
		// Just in case we are getting to exit without previous conditions being met
		// Not sure if this happens - will test.
		if(!that.isShuttingDown) {
                    that.emit('preShutdown', 'exit');
                    that._log("Application Exiting for Undefined Reason, Beginning Shutdown Process");
                    that._shutdown(null, params.timeout);
		}
	});
        EventEmitter.call(this);
}
function ShutdownManager ( params ) { // Set State var that = this ; this . isShuttingDown = false ; this . actionChain = [ ] ; this . finalActionChain = [ ] ; // Set Parameters this . logger = ( params && params . hasOwnProperty ( "logger" ) ) ? params . logger : null ; this . loggingPrefix = ( params && params . hasOwnProperty ( "loggingPrefix" ) ) ? params . loggingPrefix : DEFAULT_LOGGING_PREFIX ; // Add Process Handlers process . on ( 'SIGINT' , function ( ) { if ( ! that . emit ( 'preShutdown' , 'SIGINT' ) ) { that . _log ( "Received SIGINT, Beginning Shutdown Process" ) ; } that . _shutdown ( 128 + 2 , params . timeout ) ; } ) ; process . on ( 'SIGTERM' , function ( ) { if ( ! that . emit ( 'preShutdown' , 'SIGTERM' ) ) { that . _log ( "Received SIGTERM, Beginning Shutdown Process" ) ; } that . _shutdown ( 128 + 15 , params . timeout ) ; } ) ; process . on ( 'uncaughtException' , function ( err ) { if ( ! that . emit ( 'preShutdown' , 'uncaughtException' , err ) ) { that . _log ( 'Uncaught Exception Received, Beginning Shutdown Process' ) ; that . _log ( 'Exception: ' + err ) ; } that . _shutdown ( 255 , params . timeout ) ; } ) ; process . on ( 'exit' , function ( ) { // Just in case we are getting to exit without previous conditions being met // Not sure if this happens - will test. if ( ! that . isShuttingDown ) { that . emit ( 'preShutdown' , 'exit' ) ; that . _log ( "Application Exiting for Undefined Reason, Beginning Shutdown Process" ) ; that . _shutdown ( null , params . timeout ) ; } } ) ; EventEmitter . call ( this ) ; }
The manager class which handles detecting the shutdown process as well as managing
a chain of actions to be performed when the shutdown process has been detected.

@param params [Object]
* +logger+ - (<tt>Object</tt>) You can pass in a custom logger.  If a custom logger
is not passed in, the console will be used.
* +loggingPrefix+ - (<tt>String</tt>) The classes uses a default prefix for all log
messages.  You can pass in your own prefix instead of the default.
* +timeout+ - (<tt>Integer</tt>) If set, the timeout (in milliseconds)
for waiting for the action promises to complete.  Default is none (infinite wait)
The manager class which handles detecting the shutdown process as well as managing a chain of actions to be performed when the shutdown process has been detected .