#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Clean orphan chrome on VPS assign Nekos (currently neko-7).""" from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") FIX = r"""#!/bin/bash set -e echo '=== before ===' docker ps --format '{{.Names}}' | grep -E 'douyinweb-neko-' | sort for N in $(docker ps --format '{{.Names}}' | grep -E 'douyinweb-neko-[0-9]+$' | sort); do echo "===== $N =====" docker exec "$N" supervisorctl stop google-chrome || true sleep 1 docker exec -i "$N" python3 - <<'PY' import os, signal, time n=0 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); n+=1 except Exception: pass time.sleep(0.4) print("killed", n) 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 sleep 20 echo '=== after ===' for N in $(docker ps --format '{{.Names}}' | grep -E 'douyinweb-neko-[0-9]+$' | sort); do out=$(docker exec -i "$N" python3 - <<'PY' import os, json, urllib.request mains=0; load=False; sw=-1; trap=False try: trap=b"on_supervisor_stop" in open("/etc/neko/browser-launch.sh","rb").read() except Exception as e: trap=repr(e) 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} trap={trap}") PY ) echo "$N $out" done # quick public probe curl -sS -m 5 -o /dev/null -w 'dylive_neko7=%{http_code}\n' https://dylive.nomadro.com/neko/7/ || true """ def main() -> None: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( "107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False, banner_timeout=60, ) sftp = c.open_sftp() with sftp.file("/tmp/_fix_vps_assign_chrome_dual.sh", "w") as f: f.write(FIX) sftp.close() _i, o, e = c.exec_command("bash /tmp/_fix_vps_assign_chrome_dual.sh", timeout=300) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() if __name__ == "__main__": main()