mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
only close 0-2 fds when -R isn't specified
Following some discussion on IRC with @GrahamDumpleton this patch only close stdios if -R isn't specified. It also let others fds open and don't try to close them. This should fix logging around and behave like other daemons. It should also close #309.
This commit is contained in:
parent
cc7f595adc
commit
29aefcc1cf
@ -93,6 +93,9 @@ class Arbiter(object):
|
||||
if 'GUNICORN_FD' in os.environ:
|
||||
self.log.reopen_files()
|
||||
|
||||
if self.cfg.enable_stdio_inheritance:
|
||||
util.disable_stdout_buffering()
|
||||
|
||||
self.address = self.cfg.address
|
||||
self.num_workers = self.cfg.workers
|
||||
self.debug = self.cfg.debug
|
||||
@ -352,10 +355,6 @@ class Arbiter(object):
|
||||
os.chdir(self.START_CTX['cwd'])
|
||||
self.cfg.pre_exec(self)
|
||||
|
||||
# close all file descriptors except bound sockets
|
||||
util.closerange(3, fds[0])
|
||||
util.closerange(fds[-1] + 1, util.get_maxfd())
|
||||
|
||||
os.execvpe(self.START_CTX[0], self.START_CTX['args'], os.environ)
|
||||
|
||||
def reload(self):
|
||||
|
||||
@ -426,25 +426,15 @@ def daemonize(enable_stdio_inheritance=False):
|
||||
|
||||
os.umask(0)
|
||||
|
||||
maxfd = get_maxfd()
|
||||
if not enable_stdio_inheritance:
|
||||
closerange(0, maxfd)
|
||||
closerange(0, 3)
|
||||
|
||||
os.open(REDIRECT_TO, os.O_RDWR)
|
||||
os.dup2(0, 1)
|
||||
os.dup2(0, 2)
|
||||
fd_null = os.open(REDIRECT_TO, os.O_RDWR)
|
||||
if fd_null != 0:
|
||||
os.dup2(fd_null, 0)
|
||||
os.dup2(fd_null, 1)
|
||||
os.dup2(fd_null, 2)
|
||||
else:
|
||||
closerange(3, maxfd)
|
||||
os.open(REDIRECT_TO, os.O_RDWR)
|
||||
for stream in (sys.stdin, sys.stdout, sys.stderr):
|
||||
fd = stream.fileno()
|
||||
try:
|
||||
if stream.isatty():
|
||||
os.close(fd)
|
||||
if fd in (1, 2):
|
||||
os.dup2(0, fd)
|
||||
except AttributeError:
|
||||
pass
|
||||
disable_stdout_buffering()
|
||||
|
||||
def seed():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user