code: function shutdown(code, wait) {
    var wait  = wait || 10000;
  
    var die   = function(graceful) {
      var msg = graceful ? 'Shutdown complete.' : "Time's up, shutdown forced.";
      logger.info(msg + ' Have a jolly good day sir.\n');
      process.exit(code);
    };
  
    // we should only remove the pidfile if the agent is really running
    // otherwise a second instance would remove the pidfile of the first one
    if (agent.running()) {
      logger.info('Gracefully shutting down. Will self-destruct in ' + wait/1000 + ' secs.');
  
      var timer = setTimeout(die, wait);
      if (pidfile) pid.remove(pidfile);
  
      agent.shutdown(function() {
        clearTimeout(timer);
        // wait a tad so that everything gets flushed.
        setTimeout(function() { die(true) }, 50);
      });
    }
  }
docs: /////////////////////////////////////////////////////////// event, signal handlers ///////////////////////////////////////////////////////////