109 lines
3.7 KiB
Python
109 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Hard-kill all chrome PIDs inside neko-3 (no pkill), then single restart."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
FIX = r"""#!/bin/bash
|
|
set -e
|
|
N=douyinweb-neko-3
|
|
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 Exception:
|
|
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 as e:
|
|
print("kill_fail", pid, e)
|
|
time.sleep(0.5)
|
|
print("killed", killed)
|
|
# leftover mains?
|
|
left=[]
|
|
for pid in os.listdir("/proc"):
|
|
if not pid.isdigit(): continue
|
|
try: raw=open(f"/proc/{pid}/cmdline","rb").read()
|
|
except: continue
|
|
if b"google-chrome" in raw or b"/opt/google/chrome/chrome" in raw:
|
|
left.append((pid, raw.replace(b"\0",b" ").decode()[:80]))
|
|
print("left", left)
|
|
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
|
|
sleep 20
|
|
docker exec "$N" supervisorctl status google-chrome
|
|
docker exec -i "$N" python3 - <<'PY'
|
|
import json, os, urllib.request
|
|
from pathlib import Path
|
|
mains=[]
|
|
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.append(pid)
|
|
print("chrome_main", pid)
|
|
for part in raw.split(b"\0"):
|
|
if b"load-extension" in part:
|
|
print(" ", part.decode()[:220])
|
|
print("main_count", len(mains))
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=5).read())
|
|
sw=[t for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or "")]
|
|
print("tm_sw", len(sw), "tabs", len(tabs))
|
|
for t in tabs:
|
|
u=t.get("url") or ""
|
|
if "extension" in u or "tampermonkey" in u or t.get("type") in ("service_worker","page"):
|
|
if "doubleclick" in u or "recaptcha" in u: continue
|
|
print(" ", t.get("type"), u[:130])
|
|
les=Path("/home/neko/.config/google-chrome/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo/000003.log")
|
|
print("auto_dismiss", "YouTube Studio Auto Dismiss" in les.read_bytes().decode("utf-8","replace") if les.exists() else False)
|
|
PY
|
|
"""
|
|
|
|
|
|
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_neko3_chrome_dual2.sh", "w") as f:
|
|
f.write(FIX)
|
|
sftp.close()
|
|
_i, o, e = c.exec_command(
|
|
"echo '4669805' | sudo -S -p '' bash /tmp/_fix_neko3_chrome_dual2.sh",
|
|
timeout=120,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|