def daemonize(): """ if daemon option is set, this function will daemonize the master. It's based on this activestate recipe : http://code.activestate.com/recipes/278731/ """ if not 'GUNICORN_FD' in os.environ: if os.fork() == 0: os.setsid() if os.fork() != 0: os.umask(0) else: os._exit(0) else: os._exit(0) maxfd = util.get_maxfd() # Iterate through and close all file descriptors. for fd in range(0, maxfd): try: os.close(fd) except OSError: # ERROR, fd wasn't open to begin with (ignored) pass os.open(util.REDIRECT_TO, os.O_RDWR) os.dup2(0, 1) os.dup2(0, 2)
def reexec(self): """\ Relaunch the master and workers. """ if self.pidfile is not None: self.pidfile.rename("%s.oldbin" % self.pidfile.fname) self.reexec_pid = os.fork() if self.reexec_pid != 0: self.master_name = "Old Master" return os.environ['GUNICORN_FD'] = str(self.LISTENER.fileno()) os.chdir(self.START_CTX['cwd']) self.cfg.pre_exec(self) util.closerange(3, self.LISTENER.fileno()) util.closerange(self.LISTENER.fileno()+1, util.get_maxfd()) os.execvpe(self.START_CTX[0], self.START_CTX['args'], os.environ)
def reexec(self): """\ Relaunch the master and workers. """ if self.pidfile is not None: self.pidfile.rename("%s.oldbin" % self.pidfile.fname) self.reexec_pid = os.fork() if self.reexec_pid != 0: self.master_name = "Old Master" return fds = [l.fileno() for l in self.LISTENERS] os.environ['GUNICORN_FD'] = ",".join([str(fd) for fd in fds]) 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 daemonize(): if not 'GUNICORN_FD' in os.environ: if os.fork() == 0: os.setsid() if os.fork() == 0: os.umask(UMASK) else: os._exit(0) else: os._exit(0) maxfd = util.get_maxfd() # Iterate through and close all file descriptors. for fd in range(0, maxfd): try: os.close(fd) except OSError: # ERROR, fd wasn't open to begin with (ignored) pass os.open(util.REDIRECT_TO, os.O_RDWR) os.dup2(0, 1) os.dup2(0, 2)