def _makeImageService(self, resource_root):
from provisioningserver.rackdservices.image import (
BootImageEndpointService)
from twisted.internet.endpoints import AdoptedStreamServerEndpoint
port = 5248 # config["port"]
# Make a socket with SO_REUSEPORT set so that we can run multiple we
# applications. This is easier to do from outside of Twisted as there's
# not yet official support for setting socket options.
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
except socket_error as e:
# Python's socket module was compiled using modern headers
# thus defining SO_REUSEPORT would cause issues as it might
# running in older kernel that does not support SO_REUSEPORT.
# XXX andreserl 2015-04-08 bug=1441684: We need to add a warning
# log message when we see this error, and a test for it.
if e.errno != ENOPROTOOPT:
raise e
s.bind(('::', port))
# Use a backlog of 50, which seems to be fairly common.
s.listen(50)
# Adopt this socket into Twisted's reactor.
site_endpoint = AdoptedStreamServerEndpoint(
reactor, s.fileno(), s.family)
site_endpoint.port = port # Make it easy to get the port number.
site_endpoint.socket = s # Prevent garbage collection.
image_service = BootImageEndpointService(
resource_root=resource_root, endpoint=site_endpoint)
image_service.setName("image_service")
return image_service
评论列表
文章目录