Exemplo n.º 1
0
Arquivo: wsgi.py Projeto: e0ne/brick
    def start(self):
        """Start serving a WSGI application.

        :returns: None
        :raises: brick.exception.InvalidInput

        """
        # The server socket object will be closed after server exits,
        # but the underlying file descriptor will remain open, and will
        # give bad file descriptor error. So duplicating the socket object,
        # to keep file descriptor usable.

        dup_socket = self._socket.dup()
        if self._use_ssl:
            try:
                ssl_kwargs = {
                    'server_side': True,
                    'certfile': CONF.ssl_cert_file,
                    'keyfile': CONF.ssl_key_file,
                    'cert_reqs': ssl.CERT_NONE,
                }

                if CONF.ssl_ca_file:
                    ssl_kwargs['ca_certs'] = CONF.ssl_ca_file
                    ssl_kwargs['cert_reqs'] = ssl.CERT_REQUIRED

                dup_socket = ssl.wrap_socket(dup_socket,
                                             **ssl_kwargs)

                dup_socket.setsockopt(socket.SOL_SOCKET,
                                      socket.SO_REUSEADDR, 1)

                # sockets can hang around forever without keepalive
                network_utils.set_tcp_keepalive(dup_socket,
                                                CONF.tcp_keepalive,
                                                CONF.tcp_keepidle,
                                                CONF.tcp_keepalive_count,
                                                CONF.tcp_keepalive_interval)

            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.error(_("Failed to start %(name)s on %(_host)s:"
                                "%(_port)s with SSL support.") % self.__dict__)

        wsgi_kwargs = {
            'func': eventlet.wsgi.server,
            'sock': dup_socket,
            'site': self.app,
            'protocol': self._protocol,
            'custom_pool': self._pool,
            'log': self._wsgi_logger
        }

        self._server = eventlet.spawn(**wsgi_kwargs)
Exemplo n.º 2
0
Arquivo: wsgi.py Projeto: e0ne/brick
    def start(self):
        """Start serving a WSGI application.

        :returns: None
        :raises: brick.exception.InvalidInput

        """
        # The server socket object will be closed after server exits,
        # but the underlying file descriptor will remain open, and will
        # give bad file descriptor error. So duplicating the socket object,
        # to keep file descriptor usable.

        dup_socket = self._socket.dup()
        if self._use_ssl:
            try:
                ssl_kwargs = {
                    'server_side': True,
                    'certfile': CONF.ssl_cert_file,
                    'keyfile': CONF.ssl_key_file,
                    'cert_reqs': ssl.CERT_NONE,
                }

                if CONF.ssl_ca_file:
                    ssl_kwargs['ca_certs'] = CONF.ssl_ca_file
                    ssl_kwargs['cert_reqs'] = ssl.CERT_REQUIRED

                dup_socket = ssl.wrap_socket(dup_socket, **ssl_kwargs)

                dup_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                                      1)

                # sockets can hang around forever without keepalive
                network_utils.set_tcp_keepalive(dup_socket, CONF.tcp_keepalive,
                                                CONF.tcp_keepidle,
                                                CONF.tcp_keepalive_count,
                                                CONF.tcp_keepalive_interval)

            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.error(
                        _("Failed to start %(name)s on %(_host)s:"
                          "%(_port)s with SSL support.") % self.__dict__)

        wsgi_kwargs = {
            'func': eventlet.wsgi.server,
            'sock': dup_socket,
            'site': self.app,
            'protocol': self._protocol,
            'custom_pool': self._pool,
            'log': self._wsgi_logger
        }

        self._server = eventlet.spawn(**wsgi_kwargs)
Exemplo n.º 3
0
def remove_path_on_error(path, remove=delete_if_exists):
    """Protect code that wants to operate on PATH atomically.
    Any exception will cause PATH to be removed.

    :param path: File to work with
    :param remove: Optional function to remove passed path
    """

    try:
        yield
    except Exception:
        with excutils.save_and_reraise_exception():
            remove(path)
Exemplo n.º 4
0
def remove_path_on_error(path, remove=delete_if_exists):
    """Protect code that wants to operate on PATH atomically.
    Any exception will cause PATH to be removed.

    :param path: File to work with
    :param remove: Optional function to remove passed path
    """

    try:
        yield
    except Exception:
        with excutils.save_and_reraise_exception():
            remove(path)