douyinWEB/scripts/_fix_dylive_neko12_sigill_mount.py
2026-09-13 22:10:49 -05:00

111 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""Find real browser-launch mount source on dylive and force-patch + restart chrome."""
from __future__ import annotations
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
LOCAL = Path(__file__).resolve().parents[1] / "backend" / "neko" / "browser-launch.sh"
text = LOCAL.read_text(encoding="utf-8")
assert "no-wasm-simd" in text
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
22,
"root",
"Xiao4669805",
timeout=45,
allow_agent=False,
look_for_keys=False,
banner_timeout=120,
)
def run(cmd: str, t: int = 120) -> str:
print("\n=====", cmd[:90].replace("\n", " "), flush=True)
_i, o, e = c.exec_command(cmd, timeout=t)
out = (o.read() + e.read()).decode("utf-8", "replace")
print(out[-10000:] if len(out) > 10000 else out, flush=True)
return out
out = run(
"docker inspect douyinweb-neko-12 --format '{{range .Mounts}}{{.Source}}|{{.Destination}}|{{.Mode}}{{println}}{{end}}'"
)
# find browser-launch source
src = ""
for line in out.splitlines():
if "browser-launch" in line:
src = line.split("|")[0].strip()
print("FOUND_SRC", src)
if not src:
# fallback search
out2 = run("find /opt /root /home -name browser-launch.sh 2>/dev/null | head -20")
for line in out2.splitlines():
if line.strip().endswith("browser-launch.sh"):
src = line.strip()
break
if not src:
raise SystemExit("no browser-launch source")
sftp = c.open_sftp()
bak = f"{src}.bak-sigill2-{int(time.time())}"
try:
sftp.rename(src, bak)
print("bak", bak)
except OSError as e:
print("rename_err", e)
# copy then overwrite
run(f"cp -a '{src}' '{bak}' || true")
tmp = "/tmp/browser-launch-sigill2.sh"
with sftp.file(tmp, "wb") as f:
f.write(text.encode("utf-8"))
sftp.chmod(tmp, 0o755)
sftp.close()
run(f"cp -a {tmp} '{src}' && ls -la '{src}' && grep -n 'no-wasm-simd\\|WebAssemblySimd\\|max-old-space' '{src}'")
run(
r"""
set +e
docker exec douyinweb-neko-12 grep -n 'no-wasm-simd\|WebAssemblySimd\|max-old-space' /etc/neko/browser-launch.sh
docker exec douyinweb-neko-12 supervisorctl restart google-chrome
sleep 12
docker exec douyinweb-neko-12 supervisorctl status google-chrome
docker exec douyinweb-neko-12 sh -c 'for p in /proc/[0-9]*; do
cmd=$(tr "\0" " " < "$p/cmdline" 2>/dev/null)
case "$cmd" in
*remote-debugging-port=9222*) echo "$cmd" | tr " " "\n" | grep -E "js-flags|wasm|WebAssembly|max-old" ; break ;;
esac
done'
# reopen studio
docker exec douyinweb-neko-12 python3 -c '
import json,urllib.request,time
S="https://studio.youtube.com/channel/UCfP5vcTQEfrHc13yTmmokQw/livestreaming"
for i in range(30):
try:
urllib.request.urlopen("http://127.0.0.1:9222/json/version",timeout=2).read(); break
except Exception:
time.sleep(1)
req=urllib.request.Request("http://127.0.0.1:9222/json/new?"+S, method="PUT")
print(urllib.request.urlopen(req,timeout=15).read()[:120])
time.sleep(6)
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=5).read())
for t in tabs:
if t.get("type")=="page":
print("TAB",(t.get("title") or "")[:70], "|", (t.get("url") or "")[:120])
'
"""
)
c.close()
print("DONE")