def __check_cmd(self, cmd, env): self.logger.debug("ssd env: " + str(env)) outfile = self.__outfile if outfile: outfile = Path(outfile).open("a") try: check_call(cmd, stdout=outfile, stderr=STDOUT, close_fds=True, cwd=self.__workingdir, env=env) finally: if outfile is not None: outfile.close()
class CheckPIDFileController(DaemonController): def __init__(self, pidfile, *args, **kw): super(CheckPIDFileController, self).__init__(*args, **kw) self.__pidfile = Path(pidfile) @property def pidfile(self): return self.__pidfile @property def is_running(self): if not self.pidfile.exists(): return False if not self.pidfile.isfile(): raise Exception("pidfile '%s' is not a file" % (self.pidfile,)) try: pid = int(self.__pidfile.open().readline(16)) except: self.logger.exception("Error reading pidfile %s" % (self.pidfile)) raise try: os.kill(pid, 0) return True except OSError, e: if e.errno == errno.ESRCH: return False raise
def __init__(self, pidfile, *args, **kw): super(CheckPIDFileController, self).__init__(*args, **kw) self.__pidfile = Path(pidfile)