def main(args=sys.argv[1:]): parser = argparse.ArgumentParser(description='beepbeep ApiGateway') parser.add_argument('--fd', type=int, default=None) parser.add_argument('--config-file', help='Config file', type=str, default=None) args = parser.parse_args(args=args) app = create_app(args.config_file) host = app.config.get('host', '0.0.0.0') port = app.config.get('port', 5000) debug = app.config.get('DEBUG', False) signal.signal(signal.SIGINT, _quit) signal.signal(signal.SIGTERM, _quit) db.init_app(app) db.app = app db.create_all(app=app) init_database() if args.fd is not None: # use chaussette httpd = make_server(app, host='fd://%d' % args.fd) httpd.serve_forever() else: app.run(debug=debug, host=host, port=port, use_reloader=debug)
def runner(): if args.fd is not None: # use chaussette httpd = make_server(app, host='fd://%d' % args.fd) httpd.serve_forever() else: app.run(debug=debug, host=host, port=port)
def main(args=sys.argv[1:]): parser = argparse.ArgumentParser(description='Flask Docker Template') parser.add_argument('--fd', type=int, default=None) parser.add_argument('--config-env', "-c", help='Configuration Environment', type=str, dest='config', choices=_CONFIG_ENVIRONMENTS.keys(), default='default') args = parser.parse_args(args) config_env = args.config app = create_app(_CONFIG_ENVIRONMENTS[config_env]) port = app.config.get('PORT', 5000) host = app.config.get('HOST', '127.0.0.1') signal.signal(signal.SIGINT, _quit) signal.signal(signal.SIGTERM, _quit) if args.fd is not None: httpd = make_server(app, host=f'fd://{args.fd}') httpd.serve_forever() else: app.run(host=host, port=port)
def _make_server(): try: # instill eventlet_server instance to `_backends` dict to bypass the restriction! _backends['eventlet'] = eventlet_server app = wrap_socketio_server() httpd = make_server(app, host=host, port=port, backend='eventlet') httpd.serve_forever() except KeyboardInterrupt: sys.exit(0)
def __init__(self, host, port): register("ws4py", WebSocketChaussette) logger = configure_logger() self.server = make_server( app=WebSocketWSGIApplication(handler_cls=WebSocketGevent), host=host, port=port, backend="ws4py", address_family=socket.AF_INET, logger=logger) self.server.serve_forever()
def __init__(self, host, port): register("ws4py", WebSocketChaussette) logger = configure_logger() self.server = make_server( app=WebSocketWSGIApplication(handler_cls=WebSocketGevent), host=host, port=port, backend="ws4py", address_family=socket.AF_INET, logger=logger ) self.server.serve_forever()
def main(): args = get_args() configure_logger(logger, args.loglevel, args.logoutput) cache = None if args.cache: import pylibmc logger.info('Using the cache at %s' % args.cache) logger.info('The timeout value is set to %ss' % args.cache_timeout) cache = pylibmc.Client([args.cache]) statsd = None if args.statsd: import statsd logger.info('sending informations to statsd at %s' % args.statsd) statsd_host, statsd_port = args.statsd.split(':', 1) statsd = statsd.StatsClient(statsd_host, int(statsd_port), args.statsd_namespace) if args.excluded_paths and not cache: logger.info('--excluded-paths ignored; since no cache is being used') elif args.excluded_paths: args.excluded_paths = args.excluded_paths.split(',') logger.info('paths that will not be cached:' % args.excluded_paths) host, port = args.local.split(':') port = int(port) if not args.distant.startswith('http://'): args.distant = 'http://%s' % args.distant logger.info('Starting httpcache proxy. Listening on %s, proxying to %s, ' 'using the %s backend' % (args.local, args.distant, args.backend)) proxy = WSGIProxyApp(args.distant) app = CacheRequests(proxy, cache=cache, statsd=statsd, cache_timeout=args.cache_timeout, excluded_paths=args.excluded_paths, logger=logger) httpd = make_server(app, host, port=port, backend=args.backend) try: httpd.serve_forever() except KeyboardInterrupt: sys.exit(0) finally: logger.info('Exiting, bye!')
def main(): args = get_args() configure_logger(logger, args.loglevel, args.logoutput) cache = None if args.cache: import pylibmc logger.info('Using the cache at %s' % args.cache) logger.info('The timeout value is set to %ss' % args.cache_timeout) cache = pylibmc.Client([args.cache]) statsd = None if args.statsd: import statsd logger.info('sending informations to statsd at %s' % args.statsd) statsd_host, statsd_port = args.statsd.split(':', 1) statsd = statsd.StatsClient(statsd_host, int(statsd_port), args.statsd_namespace) if args.excluded_paths and not cache: logger.info('--excluded-paths ignored; since no cache is being used') elif args.excluded_paths: args.excluded_paths = args.excluded_paths.split(',') logger.info('paths that will not be cached:' % args.excluded_paths) host, port = args.local.split(':') port = int(port) if not args.distant.startswith('http://'): args.distant = 'http://%s' % args.distant logger.info('Starting httpcache proxy. Listening on %s, proxying to %s, ' 'using the %s backend' % (args.local, args.distant, args.backend)) proxy = WSGIProxyApp(args.distant) app = CacheRequests(proxy, cache=cache, statsd=statsd, cache_timeout=args.cache_timeout, excluded_paths=args.excluded_paths, logger=logger) httpd = make_server(app, host, port=port, backend=args.backend) try: httpd.serve_forever() except KeyboardInterrupt: sys.exit(0) finally: logger.info('Exiting, bye!')
class ws4pyServer(GeventServer): handler_class = WebSocketWSGIHandler def __init__(self, *args, **kwargs): GeventServer.__init__(self, *args, **kwargs) self.pool = GEventWebSocketPool() def stop(self, *args, **kwargs): self.pool.clear() self.pool = None GeventServer.stop(self, *args, **kwargs) if __name__ == '__main__': import os, socket_example111, sys from ws4py import configure_logger logger = configure_logger() from chaussette.backend import register register('ws4py', ws4pyServer) from chaussette.server import make_server server = make_server(app=WebSocketWSGIApplication(handler_cls=EchoWebSocket), host='unix:///%s/ws.sock' % os.getcwd(), address_family=socket_example111.AF_UNIX, backend='ws4py', logger=logger) try: server.serve_forever() except KeyboardInterrupt: sys.exit(0)
def __init__(self, *args, **kwargs): GeventServer.__init__(self, *args, **kwargs) self.pool = GEventWebSocketPool() def stop(self, *args, **kwargs): self.pool.clear() self.pool = None GeventServer.stop(self, *args, **kwargs) if __name__ == '__main__': import os, socket, sys from ws4py import configure_logger logger = configure_logger() from chaussette.backend import register register('ws4py', ws4pyServer) from chaussette.server import make_server server = make_server( app=WebSocketWSGIApplication(handler_cls=EchoWebSocket), host='unix:///%s/ws.sock' % os.getcwd(), address_family=socket.AF_UNIX, backend='ws4py', logger=logger) try: server.serve_forever() except KeyboardInterrupt: sys.exit(0)