src/server/startup.js
function Startup(options) {
  /*jshint maxcomplexity: 11 */

  options = options || {};

  this._logPrefix = util.getLogPrefix();

  this.worker = options.worker;
  if (!this.worker) {
    throw new Error('Need to provide a worker callback!');
  }
  util.verifyType('function', this, 'worker');

  this._stats = options.stats || new StatsD({
    prefix: process.env.THEHELP_APP_NAME + '.'
  });

  this.log = options.log || logShim('thehelp-cluster:startup');
  util.verifyLog(this.log);

  this.masterOptions = options.masterOptions;
  this.master = options.master || this._defaultMasterStart.bind(this);
  util.verifyType('function', this, 'master');

  this.graceful = options.graceful || Graceful.instance;
  // graceful supercedes messenger
  if (!this.graceful) {
    this.messenger = options.messenger || require('thehelp-last-ditch');
    util.verifyType('function', this, 'messenger');
  }
  else {
    util.verifyGraceful(this.graceful);
  }

  this._domain = domain.create();
  this._domain.on('error', this._onError.bind(this));

  this._process = options._process || process;
  this._cluster = options._cluster || cluster;
}
function Startup(options) {
  /*jshint maxcomplexity: 11 */

  options = options || {};

  this._logPrefix = util.getLogPrefix();

  this.worker = options.worker;
  if (!this.worker) {
    throw new Error('Need to provide a worker callback!');
  }
  util.verifyType('function', this, 'worker');

  this._stats = options.stats || new StatsD({
    prefix: process.env.THEHELP_APP_NAME + '.'
  });

  this.log = options.log || logShim('thehelp-cluster:startup');
  util.verifyLog(this.log);

  this.masterOptions = options.masterOptions;
  this.master = options.master || this._defaultMasterStart.bind(this);
  util.verifyType('function', this, 'master');

  this.graceful = options.graceful || Graceful.instance;
  // graceful supercedes messenger
  if (!this.graceful) {
    this.messenger = options.messenger || require('thehelp-last-ditch');
    util.verifyType('function', this, 'messenger');
  }
  else {
    util.verifyGraceful(this.graceful);
  }

  this._domain = domain.create();
  this._domain.on('error', this._onError.bind(this));

  this._process = options._process || process;
  this._cluster = options._cluster || cluster;
}
/*
The `constructor` requires only one parameter `worker`, a callback which
starts a worker process. Optional parameters:

+ `masterOptions` - options to be passed to the `Master` class on construction in the
default master start callback
+ `master` - a callback to start the cluster's master process
+ `errorHandler` - an alternate handler for a top-level error. Prevents `messenger` from
being called, and prevents any kind of automatic graceful shutdown.
+ `messenger` -  a `function(err, options, cb)`, defaulting to
`thehelp-last-ditch`. Passed any top-level exceptions encountered.
+ `log` - a logger object: `info`, `warn` and `error` keys with the signature
`function(string)`. By default, whatever `thehelp-log-shim` gives us.