def __init__(self, data_dir, action, files_preserve, pid_file): self.data_dir = os.path.abspath(data_dir) # attributes required by daemon runner self.stdin_path = '/dev/null' self.stdout_path = '/dev/null' self.stderr_path = '/dev/null' self.pidfile_path = pid_file self.pidfile_timeout = 5 # initialise daemon runner DaemonRunner.__init__(self, self) self.daemon_context.files_preserve = files_preserve self.action = action
def __init__(self, data_dir, action, files_preserve, pid_file): self.data_dir = os.path.abspath(data_dir) # attributes required by daemon runner self.stdin_path = '/dev/null' self.stdout_path = '/dev/null' self.stderr_path = '/dev/null' self.pidfile_path = pid_file self.pidfile_timeout = 5 # initialise daemon runner DaemonRunner.__init__(self, self) self.daemon_context.files_preserve = files_preserve self.daemon_context.initgroups = False self.action = action
def __init__(self, app): for cmd in app.EXTRA_CMDS: DaemonRunner.action_funcs[cmd] = getattr(app, cmd) self.parse_args() self._stdout_path = app.stdout_path self._stdin_path = app.stdin_path self._stderr_path = app.stderr_path with open(app.stdin_path, 'a'): pass if self.action not in self.START_CMDS: app.stdin_path = '/dev/null' app.stdout_path = '/dev/null' app.stderr_path = '/dev/null' elif self.action in self.START_CMDS: self.pidfile = make_pidlockfile(app.pidfile_path, app.pidfile_timeout) status = self._get_status() if status[0] == 1: print('app is running.') raise ValueError('app is running') self._rename_log(app.stdout_path) self._rename_log(app.stderr_path) #主微线程 self._main_let = getcurrent() def _wrap_run(func): """守护模式后,没有下面sleep, 某些(admin进程在socket.getaddrinfo)会在卡死 怀疑是gevent微线程切换问题,暂时这么处理 """ def _func(*args, **kw): sleep(0.05) return func(*args, **kw) return _func app.run = _wrap_run(app.start) DaemonRunner.__init__(self, app) self._init_signal()
def __init__(self, app): for cmd in app.EXTRA_CMDS: DaemonRunner.action_funcs[cmd] = getattr(app, cmd) self.parse_args() self._stdout_path = app.stdout_path self._stdin_path = app.stdin_path self._stderr_path = app.stderr_path if self.action not in self.START_CMDS: app.stdin_path = '/dev/null' app.stdout_path = '/dev/null' app.stderr_path = '/dev/null' elif self.action in self.START_CMDS: self.pidfile = make_pidlockfile( app.pidfile_path, app.pidfile_timeout) status = self._get_status() if status[0] == 1: print 'app is running.' raise ValueError, 'app is running' self._rename_log(app.stdout_path) self._rename_log(app.stderr_path) #主微线程 self._main_let = getcurrent() def _wrap_run(func): """守护模式后,没有下面sleep, 某些(admin进程在socket.getaddrinfo)会在卡死 怀疑是gevent微线程切换问题,暂时这么处理 """ def _func(*args, **kw): sleep(0.05) return func(*args, **kw) return _func app.run = _wrap_run(app.run) DaemonRunner.__init__(self, app) self._init_signal()