Ejemplo n.º 1
0
    def run(self):
        """
        The main loop. Exits on SIGHUP, SIGINT, SIGTERM. Returns True if
        SIGHUP was received, False otherwise.
        """
        self._web_server_addrs = os.environ.get('FCGI_WEB_SERVER_ADDRS')
        if self._web_server_addrs is not None:
            self._web_server_addrs = [x.strip() for x in self._web_server_addrs.split(',')]

        sock = self._setupSocket()

        ret = ThreadedServer.run(self, sock)

        self._cleanupSocket(sock)

        return ret
Ejemplo n.º 2
0
    def run(self):
        """
        The main loop. Exits on SIGHUP, SIGINT, SIGTERM. Returns True if
        SIGHUP was received, False otherwise.
        """
        self._web_server_addrs = os.environ.get('FCGI_WEB_SERVER_ADDRS')
        if self._web_server_addrs is not None:
            self._web_server_addrs = map(lambda x: x.strip(),
                                         self._web_server_addrs.split(','))

        sock = self._setupSocket()

        ret = ThreadedServer.run(self, sock)

        self._cleanupSocket(sock)

        return ret
Ejemplo n.º 3
0
    def run(self):
        """
        Main loop. Call this after instantiating WSGIServer. SIGHUP, SIGINT,
        SIGQUIT, SIGTERM cause it to cleanup and return. (If a SIGHUP
        is caught, this method returns True. Returns False otherwise.)
        """
        self.logger.info('%s starting up', self.__class__.__name__)

        try:
            sock = self._setupSocket()
        except socket.error as e:
            self.logger.error('Failed to bind socket (%s), exiting', e[1])
            return False

        ret = ThreadedServer.run(self, sock)

        self._cleanupSocket(sock)

        self.logger.info('%s shutting down%s', self.__class__.__name__,
                         self._hupReceived and ' (reload requested)' or '')

        return ret
Ejemplo n.º 4
0
    def run(self):
        """
        Main loop. Call this after instantiating WSGIServer. SIGHUP, SIGINT,
        SIGQUIT, SIGTERM cause it to cleanup and return. (If a SIGHUP
        is caught, this method returns True. Returns False otherwise.)
        """
        self.logger.info('%s starting up', self.__class__.__name__)

        try:
            sock = self._setupSocket()
        except socket.error as e:
            self.logger.error('Failed to bind socket (%s), exiting', str(e))
            return False

        ret = ThreadedServer.run(self, sock)

        self._cleanupSocket(sock)

        self.logger.info('%s shutting down%s', self.__class__.__name__,
                         self._hupReceived and ' (reload requested)' or '')

        return ret
Ejemplo n.º 5
0
class WSGIServer(BaseSCGIServer, ThreadedServer):
    """
    SCGI/WSGI server. For information about SCGI (Simple Common Gateway
    Interface), see http://www.mems-exchange.org/software/scgi/.

    This server is similar to SWAP http://www.idyll.org/~t/www-tools/wsgi/,
    another SCGI/WSGI server.

    It differs from SWAP in that it isn't based on scgi.scgi_server and
    therefore, it allows me to implement concurrency using threads. (Also,
    this server was written from scratch and really has no other depedencies.)
    Which server to use really boils down to whether you want multithreading
    or forking. (But as an aside, I've found scgi.scgi_server's implementation
    of preforking to be quite superior. So if your application really doesn't
    mind running in multiple processes, go use SWAP. ;)
    """
    def __init__(self,
                 application,
                 scriptName=NoDefault,
                 environ=None,
                 multithreaded=True,
                 multiprocess=False,
                 bindAddress=('localhost', 4000),
                 umask=None,
                 allowedServers=None,
                 loggingLevel=logging.INFO,
                 debug=False,
                 **kw):
        """
        scriptName is the initial portion of the URL path that "belongs"
        to your application. It is used to determine PATH_INFO (which doesn't
        seem to be passed in). An empty scriptName means your application
        is mounted at the root of your virtual host.

        environ, which must be a dictionary, can contain any additional
        environment variables you want to pass to your application.

        bindAddress is the address to bind to, which must be a string or
        a tuple of length 2. If a tuple, the first element must be a string,
        which is the host name or IPv4 address of a local interface. The
        2nd element of the tuple is the port number. If a string, it will
        be interpreted as a filename and a UNIX socket will be opened.

        If binding to a UNIX socket, umask may be set to specify what
        the umask is to be changed to before the socket is created in the
        filesystem. After the socket is created, the previous umask is
        restored.

        allowedServers must be None or a list of strings representing the
        IPv4 addresses of servers allowed to connect. None means accept
        connections from anywhere.

        loggingLevel sets the logging level of the module-level logger.
        """
        BaseSCGIServer.__init__(self,
                                application,
                                scriptName=scriptName,
                                environ=environ,
                                multithreaded=multithreaded,
                                multiprocess=multiprocess,
                                bindAddress=bindAddress,
                                umask=umask,
                                allowedServers=allowedServers,
                                loggingLevel=loggingLevel,
                                debug=debug)
        for key in ('jobClass', 'jobArgs'):
            if kw.has_key(key):
                del kw[key]
        ThreadedServer.__init__(self,
                                jobClass=Connection,
                                jobArgs=(self, ),
                                **kw)

    def run(self):
        """
        Main loop. Call this after instantiating WSGIServer. SIGHUP, SIGINT,
        SIGQUIT, SIGTERM cause it to cleanup and return. (If a SIGHUP
        is caught, this method returns True. Returns False otherwise.)
        """
        self.logger.info('%s starting up', self.__class__.__name__)

        try:
            sock = self._setupSocket()
        except socket.error, e:
            self.logger.error('Failed to bind socket (%s), exiting', e[1])
            return False

        ret = ThreadedServer.run(self, sock)

        self._cleanupSocket(sock)
        self.shutdown()

        self.logger.info('%s shutting down%s', self.__class__.__name__,
                         self._hupReceived and ' (reload requested)' or '')

        return ret
Ejemplo n.º 6
0
Archivo: ajp.py Proyecto: HiPiH/life
class WSGIServer(BaseAJPServer, ThreadedServer):
    """
    AJP1.3/WSGI server. Runs your WSGI application as a persistant program
    that understands AJP1.3. Opens up a TCP socket, binds it, and then
    waits for forwarded requests from your webserver.

    Why AJP? Two good reasons are that AJP provides load-balancing and
    fail-over support. Personally, I just wanted something new to
    implement. :)

    Of course you will need an AJP1.3 connector for your webserver (e.g.
    mod_jk) - see http://jakarta.apache.org/tomcat/connectors-doc/.
    """
    def __init__(self,
                 application,
                 scriptName='',
                 environ=None,
                 multithreaded=True,
                 multiprocess=False,
                 bindAddress=('localhost', 8009),
                 allowedServers=None,
                 loggingLevel=logging.INFO,
                 debug=False,
                 **kw):
        """
        scriptName is the initial portion of the URL path that "belongs"
        to your application. It is used to determine PATH_INFO (which doesn't
        seem to be passed in). An empty scriptName means your application
        is mounted at the root of your virtual host.

        environ, which must be a dictionary, can contain any additional
        environment variables you want to pass to your application.

        bindAddress is the address to bind to, which must be a tuple of
        length 2. The first element is a string, which is the host name
        or IPv4 address of a local interface. The 2nd element is the port
        number.

        allowedServers must be None or a list of strings representing the
        IPv4 addresses of servers allowed to connect. None means accept
        connections from anywhere.

        loggingLevel sets the logging level of the module-level logger.
        """
        BaseAJPServer.__init__(self,
                               application,
                               scriptName=scriptName,
                               environ=environ,
                               multithreaded=multithreaded,
                               multiprocess=multiprocess,
                               bindAddress=bindAddress,
                               allowedServers=allowedServers,
                               loggingLevel=loggingLevel,
                               debug=debug)
        for key in ('jobClass', 'jobArgs'):
            if kw.has_key(key):
                del kw[key]
        ThreadedServer.__init__(self,
                                jobClass=Connection,
                                jobArgs=(self, ),
                                **kw)

    def run(self):
        """
        Main loop. Call this after instantiating WSGIServer. SIGHUP, SIGINT,
        SIGQUIT, SIGTERM cause it to cleanup and return. (If a SIGHUP
        is caught, this method returns True. Returns False otherwise.)
        """
        self.logger.info('%s starting up', self.__class__.__name__)

        try:
            sock = self._setupSocket()
        except socket.error, e:
            self.logger.error('Failed to bind socket (%s), exiting', e[1])
            return False

        ret = ThreadedServer.run(self, sock)

        self._cleanupSocket(sock)
        # AJP connections are more or less persistent. .shutdown() will
        # not return until the web server lets go. So don't bother calling
        # it...
        #self.shutdown()

        self.logger.info('%s shutting down%s', self.__class__.__name__,
                         self._hupReceived and ' (reload requested)' or '')

        return ret