def main(): shutdown.install_signal_handlers() # The timezone must be set in the devappserver2 process rather than just in # the runtime so printed log timestamps are consistent and the taskqueue stub # expects the timezone to be UTC. The runtime inherits the environment. os.environ['TZ'] = 'UTC' if hasattr(time, 'tzset'): # time.tzet() should be called on Unix, but doesn't exist on Windows. time.tzset() options = PARSER.parse_args() os.environ['MY_IP_ADDRESS'] = options.host os.environ['MY_PORT'] = str(options.port) os.environ['COOKIE_SECRET'] = appscale_info.get_secret() os.environ['NGINX_HOST'] = options.nginx_host if options.pidfile: with open(options.pidfile, 'w') as pidfile: pidfile.write(str(os.getpid())) dev_server = DevelopmentServer() try: dev_server.start(options) shutdown.wait_until_shutdown() finally: dev_server.stop()
def main(): """Parses command line options and launches the API server.""" shutdown.install_signal_handlers() options = PARSER.parse_args() logging.getLogger().setLevel(constants.LOG_LEVEL_TO_PYTHON_CONSTANT[ options.dev_appserver_log_level]) # Parse the application configuration if config_paths are provided, else # provide sensible defaults. if options.config_paths: app_config = application_configuration.ApplicationConfiguration( options.config_paths, options.app_id) app_id = app_config.app_id app_root = app_config.modules[0].application_root else: app_id = (options.app_id_prefix + options.app_id if options.app_id else DEFAULT_API_SERVER_APP_ID) app_root = tempfile.mkdtemp() util.setup_environ(app_id) # pylint: disable=protected-access if options.java_app_base_url: # If the user specified a java_app_base_url, then the actual app is running # via the classic Java SDK, so we use the appropriate dispatcher that will # send requests to the Java app rather than forward them internally to a # devappserver2 module. dispatcher = _LocalJavaAppDispatcher( java_app_base_url=options.java_app_base_url) else: # TODO: Rename LocalFakeDispatcher or re-implement for # api_server.py. dispatcher = request_info_lib._LocalFakeDispatcher() request_info = wsgi_request_info.WSGIRequestInfo(dispatcher) # pylint: enable=protected-access metrics_logger = metrics.GetMetricsLogger() metrics_logger.Start( options.google_analytics_client_id, user_agent=options.google_analytics_user_agent, support_datastore_emulator=options.support_datastore_emulator, category=metrics.API_SERVER_CATEGORY) # When Cloud Datastore Emulator is invoked from api_server, it should be in # test mode, which stores in memory. options.datastore_emulator_is_test_mode = True server = create_api_server(request_info=request_info, storage_path=get_storage_path( options.storage_path, app_id), options=options, app_id=app_id, app_root=app_root) try: server.start() shutdown.wait_until_shutdown() finally: metrics.GetMetricsLogger().Stop() server.quit()
def main(): """Parses command line options and launches the API server.""" shutdown.install_signal_handlers() # Initialize logging early -- otherwise some library packages may # pre-empt our log formatting. NOTE: the level is provisional; it may # be changed based on the --debug flag. logging.basicConfig( level=logging.INFO, format= '%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s] %(message)s') options = cli_parser.create_command_line_parser( cli_parser.API_SERVER_CONFIGURATION).parse_args() logging.getLogger().setLevel(constants.LOG_LEVEL_TO_PYTHON_CONSTANT[ options.dev_appserver_log_level]) # Parse the application configuration if config_paths are provided, else # provide sensible defaults. if options.config_paths: app_config = application_configuration.ApplicationConfiguration( options.config_paths, options.app_id) app_id = app_config.app_id app_root = app_config.modules[0].application_root else: app_id = (options.app_id if options.app_id else DEFAULT_API_SERVER_APP_ID) app_root = tempfile.mkdtemp() # pylint: disable=protected-access # TODO: Rename LocalFakeDispatcher or re-implement for api_server.py. request_info = wsgi_request_info.WSGIRequestInfo( request_info_lib._LocalFakeDispatcher()) # pylint: enable=protected-access os.environ['APPLICATION_ID'] = app_id os.environ['APPNAME'] = app_id os.environ['NGINX_HOST'] = options.nginx_host def request_context(environ): return request_info.request(environ, None) server = create_api_server(request_info=request_info, storage_path=get_storage_path( options.storage_path, app_id), options=options, app_id=app_id, app_root=app_root, request_context=request_context) if options.pidfile: with open(options.pidfile, 'w') as pidfile: pidfile.write(str(os.getpid())) try: server.start() shutdown.wait_until_shutdown() finally: server.quit()
def main(): """Parses command line options and launches the API server.""" shutdown.install_signal_handlers() options = PARSER.parse_args() logging.getLogger().setLevel( constants.LOG_LEVEL_TO_PYTHON_CONSTANT[options.dev_appserver_log_level]) # Parse the application configuration if config_paths are provided, else # provide sensible defaults. if options.config_paths: app_config = application_configuration.ApplicationConfiguration( options.config_paths, options.app_id) app_id = app_config.app_id app_root = app_config.modules[0].application_root else: app_id = (options.app_id_prefix + options.app_id if options.app_id else DEFAULT_API_SERVER_APP_ID) app_root = tempfile.mkdtemp() util.setup_environ(app_id) # pylint: disable=protected-access if options.java_app_base_url: # If the user specified a java_app_base_url, then the actual app is running # via the classic Java SDK, so we use the appropriate dispatcher that will # send requests to the Java app rather than forward them internally to a # devappserver2 module. dispatcher = _LocalJavaAppDispatcher( java_app_base_url=options.java_app_base_url) else: # TODO: Rename LocalFakeDispatcher or re-implement for # api_server.py. dispatcher = request_info_lib._LocalFakeDispatcher() request_info = wsgi_request_info.WSGIRequestInfo(dispatcher) # pylint: enable=protected-access metrics_logger = metrics.GetMetricsLogger() metrics_logger.Start( options.google_analytics_client_id, user_agent=options.google_analytics_user_agent, support_datastore_emulator=options.support_datastore_emulator, category=metrics.API_SERVER_CATEGORY) # When Cloud Datastore Emulator is invoked from api_server, it should be in # test mode, which stores in memory. options.datastore_emulator_is_test_mode = True server = create_api_server( request_info=request_info, storage_path=get_storage_path(options.storage_path, app_id), options=options, app_id=app_id, app_root=app_root) try: server.start() shutdown.wait_until_shutdown() finally: metrics.GetMetricsLogger().Stop() server.quit()
def main(): """Parses command line options and launches the API server.""" shutdown.install_signal_handlers() options = PARSER.parse_args() logging.getLogger().setLevel(constants.LOG_LEVEL_TO_PYTHON_CONSTANT[ options.dev_appserver_log_level]) # Parse the application configuration if config_paths are provided, else # provide sensible defaults. if options.config_paths: app_config = application_configuration.ApplicationConfiguration( options.config_paths, options.app_id) app_id = app_config.app_id app_root = app_config.modules[0].application_root else: app_id = (options.app_id_prefix + options.app_id if options.app_id else DEFAULT_API_SERVER_APP_ID) app_root = tempfile.mkdtemp() util.setup_environ(app_id) # pylint: disable=protected-access if options.java_app_base_url: # If the user specified a java_app_base_url, then the actual app is running # via the classic Java SDK, so we use the appropriate dispatcher that will # send requests to the Java app rather than forward them internally to a # devappserver2 module. dispatcher = _LocalJavaAppDispatcher( java_app_base_url=options.java_app_base_url) else: # TODO: Rename LocalFakeDispatcher or re-implement for # api_server.py. dispatcher = request_info_lib._LocalFakeDispatcher() request_info = wsgi_request_info.WSGIRequestInfo(dispatcher) # pylint: enable=protected-access server = create_api_server(request_info=request_info, storage_path=get_storage_path( options.storage_path, app_id), options=options, app_id=app_id, app_root=app_root) try: server.start() shutdown.wait_until_shutdown() finally: server.quit()
def main(): shutdown.install_signal_handlers() # The timezone must be set in the devappserver2 process rather than just in # the runtime so printed log timestamps are consistent and the taskqueue stub # expects the timezone to be UTC. The runtime inherits the environment. os.environ['TZ'] = 'UTC' if hasattr(time, 'tzset'): # time.tzet() should be called on Unix, but doesn't exist on Windows. time.tzset() options = PARSER.parse_args() dev_server = DevelopmentServer() try: dev_server.start(options) shutdown.wait_until_shutdown() finally: dev_server.stop()
def main(): """Parses command line options and launches the API server.""" shutdown.install_signal_handlers() options = cli_parser.create_command_line_parser( cli_parser.API_SERVER_CONFIGURATION).parse_args() logging.getLogger().setLevel(constants.LOG_LEVEL_TO_PYTHON_CONSTANT[ options.dev_appserver_log_level]) # Parse the application configuration if config_paths are provided, else # provide sensible defaults. if options.config_paths: app_config = application_configuration.ApplicationConfiguration( options.config_paths, options.app_id) app_id = app_config.app_id app_root = app_config.modules[0].application_root else: app_id = (options.app_id if options.app_id else DEFAULT_API_SERVER_APP_ID) app_root = tempfile.mkdtemp() # pylint: disable=protected-access # TODO: Rename LocalFakeDispatcher or re-implement for api_server.py. request_info = wsgi_request_info.WSGIRequestInfo( request_info_lib._LocalFakeDispatcher()) # pylint: enable=protected-access os.environ['APPNAME'] = app_id os.environ['NGINX_HOST'] = options.nginx_host server = create_api_server(request_info=request_info, storage_path=get_storage_path( options.storage_path, app_id), options=options, app_id=app_id, app_root=app_root) try: server.start() shutdown.wait_until_shutdown() finally: server.quit()
def main(): shutdown.install_signal_handlers() # The timezone must be set in the devappserver2 process rather than just in # the runtime so printed log timestamps are consistent and the taskqueue stub # expects the timezone to be UTC. The runtime inherits the environment. os.environ["TZ"] = "UTC" if hasattr(time, "tzset"): # time.tzet() should be called on Unix, but doesn't exist on Windows. time.tzset() options = PARSER.parse_args() os.environ["MY_IP_ADDRESS"] = options.host os.environ["MY_PORT"] = str(options.port) os.environ["COOKIE_SECRET"] = appscale_info.get_secret() os.environ["NGINX_HOST"] = options.nginx_host dev_server = DevelopmentServer() try: dev_server.start(options) shutdown.wait_until_shutdown() finally: dev_server.stop()
def main(): shutdown.install_signal_handlers() # The timezone must be set in the devappserver2 process rather than just in # the runtime so printed log timestamps are consistent and the taskqueue stub # expects the timezone to be UTC. The runtime inherits the environment. os.environ['TZ'] = 'UTC' if hasattr(time, 'tzset'): # time.tzet() should be called on Unix, but doesn't exist on Windows. time.tzset() options = PARSER.parse_args() dev_server = DevelopmentServer() try: dev_server.start(options) shutdown.wait_until_shutdown() except: # pylint: disable=bare-except metrics.GetMetricsLogger().LogOnceOnStop( metrics.DEVAPPSERVER_CATEGORY, metrics.ERROR_ACTION, label=metrics.GetErrorDetails()) raise finally: dev_server.stop()
def main(): """Parses command line options and launches the API server.""" shutdown.install_signal_handlers() options = cli_parser.create_command_line_parser( cli_parser.API_SERVER_CONFIGURATION).parse_args() logging.getLogger().setLevel( constants.LOG_LEVEL_TO_PYTHON_CONSTANT[options.dev_appserver_log_level]) # Parse the application configuration if config_paths are provided, else # provide sensible defaults. if options.config_paths: app_config = application_configuration.ApplicationConfiguration( options.config_paths, options.app_id) app_id = app_config.app_id app_root = app_config.modules[0].application_root else: app_id = (options.app_id if options.app_id else DEFAULT_API_SERVER_APP_ID) app_root = tempfile.mkdtemp() # pylint: disable=protected-access # TODO: Rename LocalFakeDispatcher or re-implement for api_server.py. request_info = wsgi_request_info.WSGIRequestInfo( request_info_lib._LocalFakeDispatcher()) # pylint: enable=protected-access os.environ['APPNAME'] = app_id os.environ['NGINX_HOST'] = options.nginx_host server = create_api_server( request_info=request_info, storage_path=get_storage_path(options.storage_path, app_id), options=options, app_id=app_id, app_root=app_root) try: server.start() shutdown.wait_until_shutdown() finally: server.quit()
def test_install_signal_handlers(self): shutdown.install_signal_handlers() self.assertEqual(shutdown._async_terminate, signal.getsignal(signal.SIGINT)) self.assertEqual(shutdown._async_terminate, signal.getsignal(signal.SIGTERM))