mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
just reload config and stay in the loop.
This commit is contained in:
parent
e1647837d4
commit
a4fdb93757
@ -10,6 +10,7 @@ import logging
|
||||
import os
|
||||
import select
|
||||
import signal
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
@ -161,7 +162,7 @@ class Arbiter(object):
|
||||
handler()
|
||||
self.wakeup()
|
||||
except HUPSignal:
|
||||
return self.reload()
|
||||
self.reload()
|
||||
except StopIteration:
|
||||
self.halt()
|
||||
except KeyboardInterrupt:
|
||||
@ -319,10 +320,19 @@ class Arbiter(object):
|
||||
os.execvpe(self.START_CTX[0], self.START_CTX['args'], os.environ)
|
||||
|
||||
def reload(self):
|
||||
old_address = self.cfg.address
|
||||
old_listener = None
|
||||
|
||||
# reload conf
|
||||
self.app.reload()
|
||||
self.setup(self.app)
|
||||
|
||||
|
||||
# do we need to change listener ?
|
||||
if old_address != self.cfg.address:
|
||||
self.LISTENER.close()
|
||||
self.LISTENER = create_socket(self.cfg)
|
||||
self.log.info("Listening at: %s" % self.LISTENER)
|
||||
|
||||
# spawn new workers with new app & conf
|
||||
for i in range(self.app.cfg.workers):
|
||||
self.spawn_worker()
|
||||
@ -330,8 +340,18 @@ class Arbiter(object):
|
||||
# unlink pidfile
|
||||
if self.pidfile is not None:
|
||||
self.pidfile.unlink()
|
||||
|
||||
return self.run()
|
||||
|
||||
|
||||
# create new pidfile
|
||||
if self.cfg.pidfile is not None:
|
||||
self.pidfile = Pidfile(self.cfg.pidfile)
|
||||
self.pidfile.create(self.pid)
|
||||
|
||||
# set new proc_name
|
||||
util._setproctitle("master [%s]" % self.proc_name)
|
||||
|
||||
# manage workers
|
||||
self.manage_workers()
|
||||
|
||||
def murder_workers(self):
|
||||
"""\
|
||||
|
||||
@ -37,11 +37,17 @@ class BaseSocket(object):
|
||||
self.bind(sock)
|
||||
sock.setblocking(0)
|
||||
sock.listen(self.conf.backlog)
|
||||
|
||||
return sock
|
||||
|
||||
def bind(self, sock):
|
||||
sock.bind(self.address)
|
||||
|
||||
def close(self):
|
||||
try:
|
||||
self.sock.close()
|
||||
except socket.error, e:
|
||||
log.info("Error while closing socket %s" % str(e))
|
||||
del self.sock
|
||||
|
||||
class TCPSocket(BaseSocket):
|
||||
|
||||
@ -78,6 +84,10 @@ class UnixSocket(BaseSocket):
|
||||
sock.bind(self.address)
|
||||
util.chown(self.address, self.conf.uid, self.conf.gid)
|
||||
os.umask(old_umask)
|
||||
|
||||
def close(self):
|
||||
super(UnixSocket, self).close()
|
||||
os.unlink(self.address)
|
||||
|
||||
def create_socket(conf):
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user