LazyBoy2/box/stop-browser.py

18 lines
609 B
Python
Raw Permalink Normal View History

2026-09-14 09:08:35 +00:00
"""Flush Chromium before the container's init exits."""
import os, signal, time
from pathlib import Path
pids=[]
for proc in Path('/proc').iterdir():
if not proc.name.isdigit():
continue
try:
cmd=(proc/'cmdline').read_bytes().split(b'\0')
if cmd and cmd[0].endswith(b'/chromium') and not any(arg.startswith(b'--type=') for arg in cmd):
pid=int(proc.name); os.kill(pid,signal.SIGTERM); pids.append(pid)
except (OSError, ValueError):
pass
for _ in range(50):
if not any(Path(f'/proc/{pid}').exists() for pid in pids):
break
time.sleep(.1)