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 os
|
||||||
import select
|
import select
|
||||||
import signal
|
import signal
|
||||||
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
@ -161,7 +162,7 @@ class Arbiter(object):
|
|||||||
handler()
|
handler()
|
||||||
self.wakeup()
|
self.wakeup()
|
||||||
except HUPSignal:
|
except HUPSignal:
|
||||||
return self.reload()
|
self.reload()
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
self.halt()
|
self.halt()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@ -319,10 +320,19 @@ class Arbiter(object):
|
|||||||
os.execvpe(self.START_CTX[0], self.START_CTX['args'], os.environ)
|
os.execvpe(self.START_CTX[0], self.START_CTX['args'], os.environ)
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
|
old_address = self.cfg.address
|
||||||
|
old_listener = None
|
||||||
|
|
||||||
# reload conf
|
# reload conf
|
||||||
self.app.reload()
|
self.app.reload()
|
||||||
self.setup(self.app)
|
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
|
# spawn new workers with new app & conf
|
||||||
for i in range(self.app.cfg.workers):
|
for i in range(self.app.cfg.workers):
|
||||||
self.spawn_worker()
|
self.spawn_worker()
|
||||||
@ -331,7 +341,17 @@ class Arbiter(object):
|
|||||||
if self.pidfile is not None:
|
if self.pidfile is not None:
|
||||||
self.pidfile.unlink()
|
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):
|
def murder_workers(self):
|
||||||
"""\
|
"""\
|
||||||
|
|||||||
@ -37,12 +37,18 @@ class BaseSocket(object):
|
|||||||
self.bind(sock)
|
self.bind(sock)
|
||||||
sock.setblocking(0)
|
sock.setblocking(0)
|
||||||
sock.listen(self.conf.backlog)
|
sock.listen(self.conf.backlog)
|
||||||
|
|
||||||
return sock
|
return sock
|
||||||
|
|
||||||
def bind(self, sock):
|
def bind(self, sock):
|
||||||
sock.bind(self.address)
|
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):
|
class TCPSocket(BaseSocket):
|
||||||
|
|
||||||
FAMILY = socket.AF_INET
|
FAMILY = socket.AF_INET
|
||||||
@ -79,6 +85,10 @@ class UnixSocket(BaseSocket):
|
|||||||
util.chown(self.address, self.conf.uid, self.conf.gid)
|
util.chown(self.address, self.conf.uid, self.conf.gid)
|
||||||
os.umask(old_umask)
|
os.umask(old_umask)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
super(UnixSocket, self).close()
|
||||||
|
os.unlink(self.address)
|
||||||
|
|
||||||
def create_socket(conf):
|
def create_socket(conf):
|
||||||
"""
|
"""
|
||||||
Create a new socket for the given address. If the
|
Create a new socket for the given address. If the
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user