Update websockifyserver.py
Systemd or upstart socket detection and activation. Ability to activate systemd or upstart socket only on-demand.
This commit is contained in:
parent
0506b3431f
commit
07e849630e
|
|
@ -370,6 +370,16 @@ class WebSockifyServer(object):
|
|||
if self.daemon and not resource:
|
||||
raise Exception("Module 'resource' required to daemonize")
|
||||
|
||||
# Systemd or upstart socket detection
|
||||
if os.environ.get('LISTEN_PID', None) == str(os.getpid()):
|
||||
self.listen_host = "socketfromfd"
|
||||
self.listen_port = 3
|
||||
self.msg("Detected systemd socket activation, listening fd %s", self.listen_port)
|
||||
elif os.environ.get('UPSTART_EVENTS', None) == "socket":
|
||||
self.listen_host = "socketfromfd"
|
||||
self.listen_port = int(os.environ.get('UPSTART_FDS'))
|
||||
self.msg("Detected upstart socket activation, listening fd %s", self.listen_port)
|
||||
|
||||
# Show configuration
|
||||
self.msg("WebSocket server settings:")
|
||||
if self.listen_fd != None:
|
||||
|
|
@ -426,9 +436,15 @@ class WebSockifyServer(object):
|
|||
if not connect:
|
||||
flags = flags | socket.AI_PASSIVE
|
||||
|
||||
if not unix_socket:
|
||||
# Starting systemd or upstart socket
|
||||
if host == "socketfromfd":
|
||||
sock = socket.fromfd(port, socket.AF_INET, socket.SOCK_STREAM)
|
||||
if sys.version_info.major == 2:
|
||||
sock = socket.socket(_sock=sock)
|
||||
elif not unix_socket:
|
||||
addrs = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM,
|
||||
socket.IPPROTO_TCP, flags)
|
||||
|
||||
if not addrs:
|
||||
raise Exception("Could not resolve host '%s'" % host)
|
||||
addrs.sort(key=lambda x: x[0])
|
||||
|
|
|
|||
Loading…
Reference in New Issue