def pgrep()

in github-runner-ami/packer/files/runner-supervisor.py [0:0]


    def pgrep(self):
        """Check for any interesting processes we might have missed."""
        listener_found = False

        for proc in psutil.process_iter(['name', 'cmdline']):
            try:
                if proc.name() == "Runner.Worker" and proc.pid not in self.interesting_processes:
                    log.info(
                        "Found existing interesting processes, protecting from scale in %d: %s",
                        proc.pid,
                        proc.cmdline(),
                    )
                    self.interesting_processes[proc.pid] = proc
                    self.protect_from_scale_in(protect=True)
                    self.dynamodb_atomic_decrement()
                if proc.name() == "Runner.Listener":
                    listener_found = True
            except psutil.NoSuchProcess:
                # Process went away before we could
                pass

        if not listener_found:
            if self.in_termating_lifecycle:
                log.info("Runner.Listener process not found - OkayToTerminate instance")
                complete_asg_lifecycle_hook('OkayToTerminate')
            else:
                # Unprotect ourselves if somehow the runner is no longer working
                self.protect_from_scale_in(protect=False)