mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
documment the code for the systemd support
This commit is contained in:
parent
888115fafd
commit
411ec544dc
@ -135,9 +135,13 @@ def create_sockets(conf, log):
|
||||
is a string, a Unix socket is created. Otherwise
|
||||
a TypeError is raised.
|
||||
"""
|
||||
listeners = []
|
||||
|
||||
if 'LISTEN_PID' in os.environ and int(os.environ.get('LISTEN_PID')) == os.getpid():
|
||||
# Systemd support, use the sockets managed by systemd and passed to
|
||||
# gunicorn.
|
||||
# http://www.freedesktop.org/software/systemd/man/systemd.socket.html
|
||||
listeners = []
|
||||
if ('LISTEN_PID' in os.environ
|
||||
and int(os.environ.get('LISTEN_PID')) == os.getpid()):
|
||||
for i in range(int(os.environ.get('LISTEN_FDS', 0))):
|
||||
fd = i + SD_LISTEN_FDS_START
|
||||
try:
|
||||
@ -146,15 +150,18 @@ def create_sockets(conf, log):
|
||||
if isinstance(sockname, str) and sockname.startswith('/'):
|
||||
listeners.append(UnixSocket(sockname, conf, log, fd=fd))
|
||||
elif len(sockname) == 2 and '.' in sockname[0]:
|
||||
listeners.append(TCPSocket("%s:%s" % sockname, conf, log, fd=fd))
|
||||
listeners.append(TCPSocket("%s:%s" % sockname, conf, log,
|
||||
fd=fd))
|
||||
elif len(sockname) == 4 and ':' in sockname[0]:
|
||||
listeners.append(TCP6Socket("[%s]:%s" % sockname[:2], conf, log, fd=fd))
|
||||
listeners.append(TCP6Socket("[%s]:%s" % sockname[:2], conf,
|
||||
log, fd=fd))
|
||||
except socket.error:
|
||||
pass
|
||||
del os.environ['LISTEN_PID'], os.environ['LISTEN_FDS']
|
||||
|
||||
if listeners:
|
||||
log.debug('Socket activation sockets: %s', ",".join([str(l) for l in listeners]))
|
||||
log.debug('Socket activation sockets: %s',
|
||||
",".join([str(l) for l in listeners]))
|
||||
return listeners
|
||||
|
||||
# get it only once
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user