示例#1
0
文件: interfaces.py 项目: netme/lymph
    def on_start(self):
        super(WebServiceInterface, self).on_start()
        setup_logger("werkzeug")
        setup_logger("gevent")
        if self.uses_static_port:
            try:
                socket_fd = self.container.get_shared_socket_fd(self.http_port)
            except NoSharedSockets:
                pass
            except SocketNotCreated:
                logger.warning(
                    "socket for port %s wasn't created by node, binding from instance instead", self.http_port
                )
            else:
                self.http_socket = sockets.create_socket("fd://%s" % socket_fd)
        if not self.http_socket:
            address = "%s:%s" % (self.container.server.ip, self.http_port)
            self.http_socket = sockets.create_socket(address)
        self.wsgi_server = LymphWSGIServer(self.http_socket, self.application, spawn=Group(self.pool_size))
        self.wsgi_server.start()

        web_instance = ServiceInstance(
            id=self.id,
            identity=self.container.identity,
            hostname=socket.gethostname(),
            ip=self.container.server.ip,
            http_port=self.http_port,
        )
        self.container.service_registry.register(self.name, web_instance, namespace="http")
示例#2
0
    def on_start(self):
        super(WebServiceInterface, self).on_start()
        setup_logger('werkzeug')
        setup_logger('gevent')
        if self.uses_static_port:
            try:
                socket_fd = self.container.get_shared_socket_fd(self.http_port)
            except NoSharedSockets:
                pass
            except SocketNotCreated:
                logger.warning(
                    "socket for port %s wasn't created by node, binding from instance instead",
                    self.http_port)
            else:
                self.http_socket = sockets.create_socket('fd://%s' % socket_fd)
        if not self.http_socket:
            address = '%s:%s' % (self.container.server.ip, self.http_port)
            self.http_socket = sockets.create_socket(address)
        self.wsgi_server = LymphWSGIServer(self.http_socket,
                                           self.application,
                                           spawn=Group(self.pool_size))
        self.wsgi_server.start()

        web_instance = ServiceInstance(
            identity=self.container.identity,
            hostname=socket.gethostname(),
            ip=self.container.server.ip,
            http_port=self.http_port,
        )
        self.container.service_registry.register(self.name,
                                                 web_instance,
                                                 namespace='http')
示例#3
0
 def on_start(self):
     super(WebServiceInterface, self).on_start()
     try:
         socket_fd = self.container.get_shared_socket_fd(self.http_port)
     except SocketNotCreated:
         socket = create_socket('%s:%s' % (self.config.get('ip') or
                                           self.container.ip,
                                           self.http_port),
                                inheritable=True)
         socket_fd = socket.fileno()
     self.http_socket = create_socket('fd://%s' % socket_fd)
     self.wsgi_server = WSGIServer(self.http_socket, self.application, log=_LoggerStream())
     self.wsgi_server.start()
示例#4
0
 def on_start(self):
     super(WebServiceInterface, self).on_start()
     setup_logger('werkzeug')
     setup_logger('gevent')
     try:
         socket_fd = self.container.get_shared_socket_fd(self.http_port)
     except SocketNotCreated:
         logger.warning("socket for port %s wasn't created by node, binding from instance instead", self.http_port)
         address = '%s:%s' % (self.container.server.ip, self.http_port)
         self.http_socket = create_socket(address)
     else:
         self.http_socket = create_socket('fd://%s' % socket_fd)
     self.wsgi_server = LymphWSGIServer(self.http_socket, self.application, spawn=Group(self.pool_size))
     self.wsgi_server.start()
示例#5
0
 def on_start(self):
     super(WebServiceInterface, self).on_start()
     setup_logger('werkzeug')
     setup_logger('gevent')
     try:
         socket_fd = self.container.get_shared_socket_fd(self.http_port)
     except SocketNotCreated:
         logger.warning("socket for port %s wasn't created by node, binding from instance instead", self.http_port)
         address = '%s:%s' % (self.container.server.ip, self.http_port)
         self.http_socket = sockets.create_socket(address)
     else:
         self.http_socket = sockets.create_socket('fd://%s' % socket_fd)
     self.wsgi_server = LymphWSGIServer(self.http_socket, self.application, spawn=Group(self.pool_size))
     self.wsgi_server.start()
示例#6
0
 def on_start(self):
     super(WebServiceInterface, self).on_start()
     try:
         socket_fd = self.container.get_shared_socket_fd(self.http_port)
     except SocketNotCreated:
         socket = create_socket(
             '%s:%s' %
             (self.config.get('ip') or self.container.ip, self.http_port),
             inheritable=True)
         socket_fd = socket.fileno()
     self.http_socket = create_socket('fd://%s' % socket_fd)
     self.wsgi_server = WSGIServer(
         self.http_socket, Request.application(self.dispatch_request))
     self.wsgi_server.start()
示例#7
0
文件: __init__.py 项目: kashopi/lymph
 def get_shared_socket_fd(self, port):
     try:
         return self.__shared_sockets[port].fileno()
     except KeyError:
         host_port = get_unused_port()
         sock = create_socket('127.0.0.1:%s' % host_port, inheritable=True)
         self.__shared_sockets[port] = sock
         return sock.fileno()
示例#8
0
 def setUp(self):
     # XXX(Mouad): Gevent master fail n python3 with: name 'dup' is not defined.
     # A workaround is to mock lymph.utils.sockets.create_socket to return
     # a dummy socket for us.
     port = get_unused_port()
     sock = create_socket('127.0.0.1:%s' % port, inheritable=True)
     with mock.patch('lymph.utils.sockets.create_socket', return_value=sock):
         super(WebServiceTestCase, self).setUp()
示例#9
0
 def get_shared_socket_fd(self, port):
     try:
         return self.__shared_sockets[port].fileno()
     except KeyError:
         host_port = get_unused_port()
         sock = create_socket('127.0.0.1:%s' % host_port, inheritable=True)
         self.__shared_sockets[port] = sock
         return sock.fileno()
示例#10
0
 def setUp(self):
     # XXX(Mouad): Gevent master fail n python3 with: name 'dup' is not defined.
     # A workaround is to mock lymph.utils.sockets.create_socket to return
     # a dummy socket for us.
     port = get_unused_port()
     sock = create_socket('127.0.0.1:%s' % port, inheritable=True)
     with mock.patch('lymph.utils.sockets.create_socket', return_value=sock):
         super(WebServiceTestCase, self).setUp()
示例#11
0
文件: node.py 项目: torte/lymph
 def create_shared_sockets(self):
     for host, port in self._sockets:
         sock = create_socket(
             '%s:%s' % (host or self.container.server.ip, port), inheritable=True)
         self.sockets[port] = sock