in github-runner-ami/packer/files/runner-supervisor.py [0:0]
def handle_proc_event(self, sock, mask):
try:
data, (nlpid, nlgrps) = sock.recvfrom(1024)
except OSError as e:
if e.errno == errno.ENOBUFS:
return
raise
if nlpid != 0:
# Ignore messages from non-root processes
return
event, detail = proc_event.from_netlink_packet(data)
if event.what == ProcEventWhat.EXEC:
try:
proc = psutil.Process(detail.pid)
with proc.oneshot():
if proc.name() == "Runner.Worker":
log.info(
"Found new interesting processes, protecting from scale in %d: %s",
detail.pid,
proc.cmdline(),
)
self.interesting_processes[detail.pid] = proc
self.protect_from_scale_in(protect=True)
self.dynamodb_atomic_decrement()
except psutil.NoSuchProcess:
# We lost the race, process has already exited. If it was that short lived it wasn't that
# interesting anyway
pass
elif event.what == ProcEventWhat.EXIT:
if detail.pid in self.interesting_processes:
log.info("Interesting process %d exited", detail.pid)
del self.interesting_processes[detail.pid]
if not self.interesting_processes:
log.info("Watching no processes, disabling termination protection")
self.protect_from_scale_in(protect=False)
elif self.in_termating_lifecycle:
try:
proc = psutil.Process(detail.pid)
if proc.name() == "Runner.Listener":
log.info("Runner.Listener process %d exited - OkayToTerminate instance", detail.pid)
complete_asg_lifecycle_hook('OkayToTerminate')
except psutil.NoSuchProcess:
# We lost the race, process has already exited. If it was that short lived it wasn't that
# interesting anyway
pass