code: function(closeCallback, forcequit, keepglobal) {
    if (!keepglobal && this === __theApp)
      __theApp = null;
    if (closeCallback)
      this.addBeforeStopListener(closeCallback);
  
    this.gracefullyExiting = true;
    var server = this.get("server");
    var p = this._beforeStop();
    if (server) {
      p = p.then(function() {
        return new Promise(function(resolve, reject) {
          server.close(function(err) {
            if (err) reject(err);
            else resolve();
          });
        });
      });
    }
    if (forcequit) {
      var timeout = typeof forcequit == "number" ? forcequit : STOP_APP_TIMEOUT;
      setTimeout( function () {
        console.error("Could not close connections in time, forcefully shutting down");
        process.exit(1);
      }, timeout);
    }
    return p;
  }
docs: /*
  @param closeCallback invoked when app is terminated
  returns a Promise that is resolved after the app is terminated.