#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Kill orphan chrome in all physical assign Nekos; single clean restart each.""" from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") FIX = r"""#!/bin/bash set -e for i in 1 2 3 4 5 6 7 8; do N=douyinweb-neko-$i docker inspect "$N" >/dev/null 2>&1 || continue echo "===== $N =====" docker exec "$N" supervisorctl stop google-chrome || true sleep 1 docker exec -i "$N" python3 - <<'PY' import os, signal, time killed=[] for _ in range(3): for pid in list(os.listdir("/proc")): if not pid.isdigit(): continue try: raw=open(f"/proc/{pid}/cmdline","rb").read() except: continue if not raw: continue if b"google-chrome" in raw or b"/opt/google/chrome" in raw: try: os.kill(int(pid), signal.SIGKILL) killed.append(pid) except Exception: pass time.sleep(0.4) print("killed", len(killed)) PY docker exec "$N" bash -lc 'rm -f /home/neko/.config/google-chrome/SingletonCookie /home/neko/.config/google-chrome/SingletonLock /home/neko/.config/google-chrome/SingletonSocket /home/neko/.config/google-chrome/SingletonStartupLock /home/neko/.config/google-chrome/lockfile /home/neko/.config/google-chrome/DevToolsActivePort 2>/dev/null; true' docker exec "$N" supervisorctl start google-chrome done echo '===== wait =====' sleep 22 for i in 1 2 3 4 5 6 7 8; do N=douyinweb-neko-$i docker inspect "$N" >/dev/null 2>&1 || continue out=$(docker exec -i "$N" python3 - <<'PY' import os, json, urllib.request mains=0; load=False; sw=-1 for pid in os.listdir("/proc"): if not pid.isdigit(): continue try: raw=open(f"/proc/{pid}/cmdline","rb").read() except: continue if not raw: continue if b"google-chrome" in raw and b"--type=" not in raw and b"crashpad" not in raw and b"browser-launch" not in raw: mains += 1 if b"load-extension" in raw and b"dhdgff" in raw: load=True try: tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=3).read()) sw=sum(1 for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or "")) except Exception: sw=-1 print(f"mains={mains} load_ext={load} tm_sw={sw}") PY ) echo "neko-$i $out" done """ def main() -> None: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( "107.173.30.245", 4014, "eric", "4669805", timeout=45, allow_agent=False, look_for_keys=False, banner_timeout=120, ) sftp = c.open_sftp() with sftp.file("/tmp/_fix_all_assign_chrome_dual.sh", "w") as f: f.write(FIX) sftp.close() _i, o, e = c.exec_command( "echo '4669805' | sudo -S -p '' bash /tmp/_fix_all_assign_chrome_dual.sh", timeout=300, ) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() if __name__ == "__main__": main()