[FIX] server: Do not listen when --no-xmlrpc is set
This is a fix for f04f409943
, which only
prevented the workers from being spawned in Prefork mode, while the
socket was still being bound to - this is a problem when starting a
worker-only server as it cannot coexist with the XMLRPC server on the
same machine.
Closes #1828
This commit is contained in:
parent
9c28b6fbfa
commit
dbdc8e1cef
|
@ -428,7 +428,8 @@ class PreforkServer(CommonServer):
|
|||
"""
|
||||
def __init__(self, app):
|
||||
# config
|
||||
self.address = (config['xmlrpc_interface'] or '0.0.0.0', config['xmlrpc_port'])
|
||||
self.address = config['xmlrpc'] and \
|
||||
(config['xmlrpc_interface'] or '0.0.0.0', config['xmlrpc_port'])
|
||||
self.population = config['workers']
|
||||
self.timeout = config['limit_time_real']
|
||||
self.limit_request = config['limit_request']
|
||||
|
@ -603,6 +604,7 @@ class PreforkServer(CommonServer):
|
|||
signal.signal(signal.SIGQUIT, dumpstacks)
|
||||
signal.signal(signal.SIGUSR1, log_ormcache_stats)
|
||||
|
||||
if self.address:
|
||||
# listen to socket
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
|
@ -632,6 +634,7 @@ class PreforkServer(CommonServer):
|
|||
_logger.info("Stopping forcefully")
|
||||
for pid in self.workers.keys():
|
||||
self.worker_kill(pid, signal.SIGTERM)
|
||||
if self.socket:
|
||||
self.socket.close()
|
||||
|
||||
def run(self, preload, stop):
|
||||
|
@ -735,11 +738,13 @@ class Worker(object):
|
|||
_logger.info("Worker %s (%s) alive", self.__class__.__name__, self.pid)
|
||||
# Reseed the random number generator
|
||||
random.seed()
|
||||
# Prevent fd inherientence close_on_exec
|
||||
if self.multi.socket:
|
||||
# Prevent fd inheritance: close_on_exec
|
||||
flags = fcntl.fcntl(self.multi.socket, fcntl.F_GETFD) | fcntl.FD_CLOEXEC
|
||||
fcntl.fcntl(self.multi.socket, fcntl.F_SETFD, flags)
|
||||
# reset blocking status
|
||||
self.multi.socket.setblocking(0)
|
||||
|
||||
signal.signal(signal.SIGINT, self.signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal.SIG_DFL)
|
||||
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
|
||||
|
@ -857,6 +862,7 @@ class WorkerCron(Worker):
|
|||
def start(self):
|
||||
os.nice(10) # mommy always told me to be nice with others...
|
||||
Worker.start(self)
|
||||
if self.multi.socket:
|
||||
self.multi.socket.close()
|
||||
|
||||
#----------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue