24 lines
1020 B
Python
24 lines
1020 B
Python
#!/usr/bin/env python3
|
|
"""Sweep only Rocko122 node/chromium processes. Never match another seat/live copy."""
|
|
import os,pathlib,signal,time,json,sys
|
|
root='/mnt/storage/src/mosaic-stack-rocko-122-r2'
|
|
def owned():
|
|
found=[]
|
|
for p in pathlib.Path('/proc').glob('[0-9]*'):
|
|
try:
|
|
argv=(p/'cmdline').read_bytes().split(b'\0');exe=pathlib.Path(argv[0].decode()).name;cwd=os.readlink(p/'cwd')
|
|
if exe not in ['node','chromium','chrome','chrome_crashpad_handler']:continue
|
|
if cwd==root or cwd.startswith(root+'/') or any(root.encode() in a for a in argv):found.append({'pid':int(p.name),'exe':exe,'cwd':cwd})
|
|
except (OSError,UnicodeError):continue
|
|
return found
|
|
before=owned();print(json.dumps({'before':before}))
|
|
for row in before:
|
|
try:os.kill(row['pid'],signal.SIGTERM)
|
|
except ProcessLookupError:pass
|
|
if before:time.sleep(1)
|
|
for row in owned():
|
|
try:os.kill(row['pid'],signal.SIGKILL)
|
|
except ProcessLookupError:pass
|
|
if before:time.sleep(.2)
|
|
after=owned();print(json.dumps({'after':after}));sys.exit(bool(after))
|