def main():
  # Required so PDB prompts work properly. Originally tried to disable buffering
  # (both by adding the -u flag when starting this process and by adding
  # "stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)" but neither worked).
  sys.stdout = AutoFlush(sys.stdout)
  assert len(sys.argv) == 3
  child_in_path = sys.argv[1]
  config = runtime_config_pb2.Config()
  config.ParseFromString(open(child_in_path, 'rb').read())
  os.remove(child_in_path)
  debugging_app = None
  if config.python_config and config.python_config.startup_script:
    global_vars = {'config': config}
    try:
      execfile(config.python_config.startup_script, global_vars)
    except Exception as e:
      debugging_app = StartupScriptFailureApplication(config,
                                                      str(e),
                                                      traceback.format_exc())

  # This line needs to be before enabling the sandbox because os.environ is
  # patched away.
  port = os.environ['PORT']
  if debugging_app:
    server = wsgi_server.WsgiServer(
        ('localhost', port),
        debugging_app)
  else:
    setup_stubs(config)
    sandbox.enable_sandbox(config)
    os.path.expanduser = expand_user
    # This import needs to be after enabling the sandbox so the runtime
    # implementation imports the sandboxed version of the logging module.
    # pylint: disable=g-import-not-at-top
    from google.appengine.tools.devappserver2.python.runtime import (
        request_handler)
    # pylint: enable=g-import-not-at-top
    server = wsgi_server.WsgiServer(
        ('localhost', port),
        request_rewriter.runtime_rewriter_middleware(
            request_handler.RequestHandler(config)))
  # Delete devappserver2.python.runtime and devappserver2.python.runtime.sandbox
  # from sys.modules so that future attempts to import
  # devappserver2.python.runtime.sandbox from user code goes through and gets
  # blocked by the sandbox's sys.meta_path import hooks.
  del sys.modules[sandbox.__name__]
  del sys.modules[runtime.__name__]
  server.start()
  try:
    while True:
      time.sleep(1)
  except KeyboardInterrupt:
    pass
  finally:
    server.quit()
    def start(self, api_host, api_port, request_data):
        """Starts the configured modules.

    Args:
      api_host: The hostname that APIServer listens for RPC requests on.
      api_port: The port that APIServer listens for RPC requests on.
      request_data: A wsgi_request_info.WSGIRequestInfo that will be provided
          with request information for use by API stubs.
    """
        self._api_host = api_host
        self._api_port = api_port
        self._request_data = request_data
        port = self._port
        self._executor.start()
        if self._configuration.dispatch:
            self._dispatch_server = wsgi_server.WsgiServer((self._host, port),
                                                           self)
            self._dispatch_server.start()
            logging.info('Starting dispatcher running at: http://%s:%s',
                         self._host, self._dispatch_server.port)
            self._update_checking_thread.start()
            if port:
                port += 1
            self._port_registry.add(self._dispatch_server.port, None, None)
        for module_configuration in self._configuration.modules:
            self._module_configurations[
                module_configuration.module_name] = module_configuration
            _module, port = self._create_module(module_configuration, port)
            _module.start()
            self._module_name_to_module[
                module_configuration.module_name] = _module
            logging.info('Starting module "%s" running at: http://%s',
                         module_configuration.module_name,
                         _module.balanced_address)
Beispiel #3
0
    def start(self, api_host, api_port, request_data):
        """Starts the configured modules.

    Args:
      api_host: The hostname that APIServer listens for RPC requests on.
      api_port: The port that APIServer listens for RPC requests on.
      request_data: A wsgi_request_info.WSGIRequestInfo that will be provided
          with request information for use by API stubs.

    Raises:
      RuntimeError: In case of cannot find port for a service.
    """
        self._api_host = api_host
        self._api_port = api_port
        self._request_data = request_data
        self._executor.start()
        if self._configuration.dispatch:
            self._dispatch_server = wsgi_server.WsgiServer(
                (self._host, self._default_port), self)
            self._dispatch_server.start()
            logging.info('Starting dispatcher running at: http://%s:%s',
                         self._host, self._dispatch_server.port)
            self._update_checking_thread.start()
            self._port_registry.add(self._dispatch_server.port, None, None)

        next_available_port = self._default_port
        for module_configuration in self._configuration.modules:
            service_name = module_configuration.module_name
            self._module_configurations[service_name] = module_configuration

            service_port = 0
            if service_name in self._specified_service_ports:
                service_port = self._specified_service_ports[service_name]
            elif next_available_port:
                next_available_port = self._find_next_available_port(
                    next_available_port, service_name)
                service_port = next_available_port

            # If necessary, find an additional port to bind to for accepting https
            # connections
            ssl_port = None
            if self._ssl_certificate_paths:
                if self._test_ssl_port is None:
                    ssl_port = self._find_next_available_port(
                        service_port + 1, service_name)
                else:
                    ssl_port = self._test_ssl_port
                    self._test_ssl_port = None

            _service = self._create_module(module_configuration, service_port,
                                           ssl_port)
            _service.start()
            self._module_name_to_module[
                module_configuration.module_name] = _service

            log_message = 'Starting module "%s" running at: http://%s' % (
                module_configuration.module_name, _service.balanced_address)
            if ssl_port:
                log_message += ' and https://%s:%s' % (self._host, ssl_port)
            logging.info(log_message)
Beispiel #4
0
    def start(self, api_port, request_data):
        """Starts the configured servers.

    Args:
      api_port: The port that APIServer listens for RPC requests on.
      request_data: A wsgi_request_info.WSGIRequestInfo that will be provided
          with request information for use by API stubs.
    """
        self._api_port = api_port
        self._request_data = request_data
        port = self._port
        self._executor.start()
        if self._configuration.dispatch:
            self._dispatch_server = wsgi_server.WsgiServer((self._host, port),
                                                           self)
            self._dispatch_server.start()
            logging.info('Starting dispatcher running at: http://%s:%s',
                         self._host, self._dispatch_server.port)
            self._update_checking_thread.start()
            if port:
                port += 100
            self._port_registry.add(self._dispatch_server.port, None, None)
        for server_configuration in self._configuration.servers:
            self._server_configurations[
                server_configuration.server_name] = server_configuration
            servr, port = self._create_server(server_configuration, port)
            servr.start()
            self._server_name_to_server[
                server_configuration.server_name] = servr
            logging.info('Starting server "%s" running at: http://%s',
                         server_configuration.server_name,
                         servr.balanced_address)
Beispiel #5
0
def main():
    # Required so PDB prompts work properly. Originally tried to disable buffering
    # (both by adding the -u flag when starting this process and by adding
    # "stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)" but neither worked).
    sys.stdout = AutoFlush(sys.stdout)
    assert len(sys.argv) == 3
    child_in_path = sys.argv[1]
    child_out_path = sys.argv[2]
    config = runtime_config_pb2.Config()
    config.ParseFromString(open(child_in_path, 'rb').read())
    os.remove(child_in_path)
    child_out = open(child_out_path, 'wb')
    debugging_app = None
    if config.python_config and config.python_config.startup_script:
        global_vars = {'config': config}
        try:
            exec(
                compile(
                    open(config.python_config.startup_script).read(),
                    config.python_config.startup_script, 'exec'), global_vars)
        except Exception as e:
            debugging_app = StartupScriptFailureApplication(
                config, str(e), traceback.format_exc())

    if debugging_app:
        server = wsgi_server.WsgiServer(('localhost', 0), debugging_app)
    else:
        setup_stubs(config)
        sandbox.enable_sandbox(config)
        # This import needs to be after enabling the sandbox so the runtime
        # implementation imports the sandboxed version of the logging module.
        from google.appengine.tools.devappserver2.python import request_handler

        server = wsgi_server.WsgiServer(
            ('localhost', 0),
            request_rewriter.runtime_rewriter_middleware(
                request_handler.RequestHandler(config)))
    server.start()
    child_out.write('{}\n'.format(server.port).encode())
    child_out.close()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass
    finally:
        server.quit()
Beispiel #6
0
    def start(self, api_host, api_port, request_data):
        """Starts the configured modules.

    Args:
      api_host: The hostname that APIServer listens for RPC requests on.
      api_port: The port that APIServer listens for RPC requests on.
      request_data: A wsgi_request_info.WSGIRequestInfo that will be provided
          with request information for use by API stubs.

    Raises:
      RuntimeError: In case of cannot find port for a service.
    """
        self._api_host = api_host
        self._api_port = api_port
        self._request_data = request_data
        self._executor.start()
        if self._configuration.dispatch:
            self._dispatch_server = wsgi_server.WsgiServer(
                (self._host, self._default_port), self)
            self._dispatch_server.start()
            logging.info('Starting dispatcher running at: http://%s:%s',
                         self._host, self._dispatch_server.port)
            self._update_checking_thread.start()
            self._port_registry.add(self._dispatch_server.port, None, None)

        next_available_port = self._default_port
        for module_configuration in self._configuration.modules:
            service_name = module_configuration.module_name
            self._module_configurations[service_name] = module_configuration

            service_port = 0
            if service_name in self._specified_service_ports:
                service_port = self._specified_service_ports[service_name]
            elif next_available_port:
                while self._port_registry.has(next_available_port):
                    next_available_port += 1
                if next_available_port >= (1 << 16):
                    raise RuntimeError('Cannot find port for service %s' %
                                       service_name)
                service_port = next_available_port

            _service = self._create_module(module_configuration, service_port)
            _service.start()
            self._module_name_to_module[
                module_configuration.module_name] = _service
            logging.info('Starting module "%s" running at: http://%s',
                         module_configuration.module_name,
                         _service.balanced_address)
Beispiel #7
0
def main():
    config = runtime_config_pb2.Config()
    config.ParseFromString(base64.b64decode(sys.stdin.read()))
    server = wsgi_server.WsgiServer(
        ('localhost', 0),
        request_rewriter.runtime_rewriter_middleware(PHPRuntime(config)))
    server.start()
    print server.port
    sys.stdout.close()
    sys.stdout = sys.stderr
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass
    finally:
        server.quit()
Beispiel #8
0
 def setUp(self):
     self.mox = mox.Mox()
     self.server = wsgi_server.WsgiServer(('localhost', 0), None)
Beispiel #9
0
  debugging_app = None
  if config.python_config and config.python_config.startup_script:
    global_vars = {'config': config}
    try:
      execfile(config.python_config.startup_script, global_vars)
    except Exception, e:
      debugging_app = StartupScriptFailureApplication(config,
                                                      str(e),
                                                      traceback.format_exc())

  # This line needs to be before enabling the sandbox because os.environ is
  # patched away.
  port = os.environ['PORT']
  if debugging_app:
    server = wsgi_server.WsgiServer(
        ('localhost', port),
        debugging_app)
  else:
    setup_stubs(config)
    sandbox.enable_sandbox(config)
    # This import needs to be after enabling the sandbox so the runtime
    # implementation imports the sandboxed version of the logging module.
    from google.appengine.tools.devappserver2.python import request_handler

    server = wsgi_server.WsgiServer(
        ('localhost', port),
        request_rewriter.runtime_rewriter_middleware(
            request_handler.RequestHandler(config)))
  server.start()
  try:
    while True: