def start_server(app): sock = eventlet.listen((cfg.CONF.host, cfg.CONF.port), backlog=500) if sslutils.is_enabled(): LOG.info(_LI("Using HTTPS for port %s"), cfg.CONF.port) sock = sslutils.wrap(sock) wsgi.server(sock, app, log=loggers.WritableLogger(LOG), debug=False)
def start(self, application): """Run a WSGI server with the given application. :param application: The application to run in the WSGI server """ def kill_children(*args): """Kills the entire process group.""" LOG.error(_LE('SIGTERM received')) signal.signal(signal.SIGTERM, signal.SIG_IGN) self.running = False os.killpg(0, signal.SIGTERM) def hup(*args): """Shuts down the server(s). Shuts down the server(s), but allows running requests to complete """ LOG.error(_LE('SIGHUP received')) signal.signal(signal.SIGHUP, signal.SIG_IGN) os.killpg(0, signal.SIGHUP) signal.signal(signal.SIGHUP, hup) self.application = application self.sock = eventlet.listen((CONF.host, CONF.port), backlog=500) if sslutils.is_enabled(): LOG.info(_LI("Using HTTPS for port %s"), CONF.port) self.sock = sslutils.wrap(self.sock) if CONF.api_workers == 0: # Useful for profiling, test, debug etc. self.pool = eventlet.GreenPool(size=self.threads) self.pool.spawn_n(self._single_run, application, self.sock) return LOG.debug("Starting %d workers", CONF.api_workers) signal.signal(signal.SIGTERM, kill_children) signal.signal(signal.SIGHUP, hup) while len(self.children) < CONF.api_workers: self.run_child()