#!/usr/bin/env python3 """Deploy SIGILL chrome flags to dylive + recover neko-12 Studio tab.""" from __future__ import annotations import sys import time from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") HOST = "107.173.50.68" # correct dylive: HOST = "107.173.30.245" PASS = "Xiao4669805" REMOTE = "/opt/douyinWEB/backend/neko/browser-launch.sh" LOCAL = Path(__file__).resolve().parents[1] / "backend" / "neko" / "browser-launch.sh" STUDIO = "https://studio.youtube.com/channel/UCfP5vcTQEfrHc13yTmmokQw/livestreaming" def main() -> None: assert LOCAL.is_file(), LOCAL text = LOCAL.read_text(encoding="utf-8") assert "no-wasm-simd" in text, "local patch missing" assert "WebAssemblySimd" in text, "local patch missing" c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( HOST, 22, "root", PASS, timeout=45, allow_agent=False, look_for_keys=False, banner_timeout=120, ) sftp = c.open_sftp() bak = f"{REMOTE}.bak-sigill-{int(time.time())}" try: sftp.stat(REMOTE) sftp.rename(REMOTE, bak) print("backed_up", bak) except OSError as e: print("no_bak", e) tmp = "/tmp/browser-launch-sigill.sh" with sftp.file(tmp, "wb") as f: f.write(text.encode("utf-8")) sftp.chmod(tmp, 0o755) sftp.close() def run(cmd: str, t: int = 180) -> str: print("\n=====", cmd[:80].replace("\n", " "), flush=True) _i, o, e = c.exec_command(cmd, timeout=t) out = (o.read() + e.read()).decode("utf-8", "replace") print(out[-12000:] if len(out) > 12000 else out, flush=True) return out run(f"cp -a {tmp} {REMOTE} && grep -n 'no-wasm-simd\\|WebAssemblySimd' {REMOTE}") run( r""" set +e sync; echo 3 > /proc/sys/vm/drop_caches free -h | head -3 docker exec douyinweb-neko-12 grep -n 'no-wasm-simd\|WebAssemblySimd' /etc/neko/browser-launch.sh docker exec douyinweb-neko-12 supervisorctl restart google-chrome sleep 10 docker exec douyinweb-neko-12 supervisorctl status google-chrome """ ) run( rf""" docker exec douyinweb-neko-12 python3 - <<'PY' import json, urllib.request, time STUDIO = "{STUDIO}" for i in range(40): try: with urllib.request.urlopen("http://127.0.0.1:9222/json/version", timeout=2) as r: print("devtools", r.status) break except Exception: time.sleep(1) else: raise SystemExit("devtools_fail") def get(url, method=None): req = urllib.request.Request(url, method=method) if method else url with urllib.request.urlopen(req, timeout=10) as r: return r.read() # open studio tab opened = False for meth in ("PUT", "GET"): try: body = get("http://127.0.0.1:9222/json/new?" + STUDIO, method=meth) print("new", meth, body[:180]) opened = True break except Exception as e: print("new_fail", meth, e) if not opened: raise SystemExit("cannot open studio tab") time.sleep(6) tabs = json.loads(get("http://127.0.0.1:9222/json/list")) for t in tabs: if t.get("type") == "page": print("TAB", (t.get("title") or "")[:70], "|", (t.get("url") or "")[:120]) PY free -h | head -3 dmesg -T 2>/dev/null | grep -iE 'invalid opcode|oom-kill' | tail -8 """ ) c.close() print("DONE") if __name__ == "__main__": main()