def restart_one(root_cg, grace_period, container_id): q = queue.Queue() cg = Cgroup(os.path.join(root_cg, container_id)) try: restart(grace_period, cg, q, q) except IOError: logger.error("%s: container does not exist", cg.name()) return 1 finally: while not q.empty(): m = q.get() logger.debug("%s: received %s", cg.name(), m.__class__.__name__) return 0
def sync(self): logger.debug("syncing cgroups") # Sync all monitors with disk, and deregister stale ones. It's # important to actually *wakeup* monitors here, so as to ensure we # don't race with Docker when it creates a cgroup (which could result # in us not seeing the memory limit and therefore not disabling the OOM # killer). for cg in list(self._path_hash.values()): try: cg.wakeup(self.job_queue, None, raise_for_stale=True) except EnvironmentError: self.deregister(cg) cg.close() for entry in os.listdir(self.root_cg_path): path = os.path.join(self.root_cg_path, entry) # Is this a CG or just a regular file? if not os.path.isdir(path): continue # We're already tracking this CG. It *might* have changed between # our check and now, but in that case we'll catch it at the next # sync. if path in self._path_hash: continue # This a new CG, Register and wake it up immediately after in case # there already is some handling to do (typically: disabling the # OOM killer). cg = Cgroup(path) try: cg.open() except EnvironmentError as e: # CG exited before we had a chance to register it. That's OK. logger.warning("%s: error opening new cg: %s", cg.name(), e) else: self.register(cg) cg.wakeup(self.job_queue, None)
def sync(self): logger.debug("syncing cgroups") # Sync all monitors with disk, and remove stale ones. It's important to # actually *wakeup* monitors here, so as to ensure we don't race with # Docker when it creates a cgroup (which could result in us not seeing # the memory limit and therefore not disabling the OOM killer). for cg in list(self._path_hash.values()): try: cg.wakeup(self.job_queue, raise_for_stale=True) except EnvironmentError: logger.info("%s: deregistering", cg.name()) self.remove(cg) for entry in os.listdir(self.root_cg_path): path = os.path.join(self.root_cg_path, entry) # Is this a CG or just a regular file? if not os.path.isdir(path): continue # We're already tracking this CG. It *might* have changed between # our check and now, but in that case we'll catch it at the next # sync. if path in self._path_hash: continue # This a new CG, register it. cg = Cgroup(path) logger.info("%s: new cgroup", cg.name()) # Register and wake up the CG immediately after, in case there # already is some handling to do (typically: disabling the OOM # killer). To avoid race conditions, we do this after registration # to ensure we can deregister immediately if the cgroup just # exited. self.register(cg) cg.wakeup(self.job_queue)