#!/usr/bin/env python3 """Recover dy neko-7: start, deploy jitless launch, probe Studio stability.""" from __future__ import annotations import sys import time from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") HOST = "108.174.50.68" PASS = "Xiao4669805" LOCAL = Path(__file__).resolve().parents[1] / "backend" / "neko" / "browser-launch.sh" STUDIO = "https://studio.youtube.com/channel/UC6ZbNjX9jg6-AeQrqwday8Q/livestreaming" def connect(): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(8): try: c.connect( HOST, 22, "root", PASS, timeout=45, allow_agent=False, look_for_keys=False, banner_timeout=180, ) return c except Exception as e: print("retry", i, e, flush=True) time.sleep(2 + i) raise SystemExit("ssh fail") def run(c, cmd, t=360): print("\n=====", cmd[:100].replace("\n", " "), flush=True) _i, o, e = c.exec_command(cmd, timeout=t) out = (o.read() + e.read()).decode("utf-8", "replace") print(out[-16000:] if len(out) > 16000 else out, flush=True) return out # ensure local has jitless text = LOCAL.read_text(encoding="utf-8") if "--jitless" not in text: text = text.replace( '--js-flags="--max-old-space-size=192 --no-wasm-simd --no-turbofan"', '--js-flags="--max-old-space-size=192 --jitless --no-wasm-simd"', ) text = text.replace( '--js-flags="--max-old-space-size=192 --no-wasm-simd"', '--js-flags="--max-old-space-size=192 --jitless --no-wasm-simd"', ) if "OPENSSL_ia32cap" not in text: text = text.replace( " echo -800 > /proc/self/oom_score_adj 2>/dev/null || true\n \"$@\" &", ' export OPENSSL_ia32cap="~0x200000200000000"\n' " echo -800 > /proc/self/oom_score_adj 2>/dev/null || true\n \"$@\" &\n", 1, ) LOCAL.write_text(text, encoding="utf-8") text = LOCAL.read_text(encoding="utf-8") assert "--jitless" in text c = connect() sftp = c.open_sftp() tmp = "/tmp/browser-launch-jitless2.sh" with sftp.file(tmp, "wb") as f: f.write(text.encode("utf-8")) sftp.chmod(tmp, 0o755) sftp.close() # Remote python as separate file to avoid f-string/brace hell remote_py = r''' import json, urllib.request, time, subprocess, os STUDIO = os.environ["STUDIO"] def cdp(path, method=None): url = "http://127.0.0.1:9222" + path req = urllib.request.Request(url, method=method) if method else url with urllib.request.urlopen(req, timeout=20) as r: return r.read() for i in range(50): try: cdp("/json/version") print("devtools_ok") break except Exception: time.sleep(1) else: raise SystemExit("no_devtools") tabs = json.loads(cdp("/json/list")) for t in tabs: if t.get("type") == "page" and t.get("id"): try: cdp("/json/close/" + t["id"]) print("closed", (t.get("url") or "")[:80]) except Exception as e: print("close_err", e) print("open", cdp("/json/new?" + STUDIO, method="PUT")[:120]) ok = False for i in range(15): time.sleep(2) tabs = json.loads(cdp("/json/list")) pages = [t for t in tabs if t.get("type") == "page"] for t in pages: print("t%s" % i, (t.get("title") or "")[:70], "|", (t.get("url") or "")[:110]) titles = " ".join((t.get("title") or "") for t in pages) urls = " ".join((t.get("url") or "") for t in pages) bad = ("Snap" in titles) or ("SIGILL" in titles) or ("chrome-error" in urls) or ("Can't open" in titles) or ("Cant open" in titles) good = ("studio.youtube.com" in urls) and ("livestreaming" in urls) and (not bad) if good: print("STUDIO_OK") ok = True break if not ok: print("STUDIO_STILL_BAD") ''' sftp = c.open_sftp() with sftp.file("/tmp/neko7_cdp_probe.py", "w") as f: f.write(remote_py) sftp.close() run( c, rf""" set -euo pipefail export DY_NEKO_NAT1TO1=108.174.50.68 export DY_NEKO_VPS_NAT1TO1=108.174.50.68 # sync launch script to all copies for f in /opt/douyinWEB/backend/neko/browser-launch.sh /opt/douyinWEB/backend/neko/browser-launch.sh.bak-sigill*; do [ -e "$f" ] || continue cat {tmp} > "$f" 2>/dev/null || true done cat {tmp} > /opt/douyinWEB/backend/neko/browser-launch.sh chmod 755 /opt/douyinWEB/backend/neko/browser-launch.sh grep -n jitless /opt/douyinWEB/backend/neko/browser-launch.sh | head # start or recreate neko-7 cd /opt/douyinWEB/backend set -a; source /etc/douyinweb.env; set +a export DY_NEKO_NAT1TO1=108.174.50.68 docker start douyinweb-neko-7 2>/dev/null || true sleep 2 if ! docker ps --format '{{{{.Names}}}}' | grep -qx douyinweb-neko-7; then echo NEED_ENSURE ./.venv/bin/python - <<'PY' from app import youtube_neko as yn print(yn.ensure_capacity(8, start_instances={{7}}, reconcile_running=True)) print('nat', yn._detect_public_ip() if hasattr(yn,'_detect_public_ip') else None) PY fi docker ps -a --filter name=douyinweb-neko-7 --format '{{{{.Names}}}} {{{{.Status}}}}' sleep 5 # overwrite mounted inode INO=$(docker exec douyinweb-neko-7 sh -c 'ls -li /etc/neko/browser-launch.sh' | awk '{{print $1}}') MATCH=$(ls -li /opt/douyinWEB/backend/neko/browser-launch.sh* | awk -v i="$INO" '$1==i{{print $NF; exit}}') echo INO=$INO MATCH=$MATCH [ -n "$MATCH" ] && cat {tmp} > "$MATCH" cat {tmp} > /opt/douyinWEB/backend/neko/browser-launch.sh docker exec douyinweb-neko-7 grep -n jitless /etc/neko/browser-launch.sh # if still no jitless -> force recreate if ! docker exec douyinweb-neko-7 grep -q jitless /etc/neko/browser-launch.sh; then WD=$(docker inspect douyinweb-neko-7 --format '{{{{index .Config.Labels "com.docker.compose.project.working_dir"}}}}') PROJ=$(docker inspect douyinweb-neko-7 --format '{{{{index .Config.Labels "com.docker.compose.project"}}}}') SVC=$(docker inspect douyinweb-neko-7 --format '{{{{index .Config.Labels "com.docker.compose.service"}}}}') echo RECREATE $WD $PROJ $SVC cd "$WD" docker compose -p "$PROJ" up -d --force-recreate --no-deps "$SVC" sleep 12 docker exec douyinweb-neko-7 grep -n jitless /etc/neko/browser-launch.sh fi docker exec douyinweb-neko-7 sh -c 'google-chrome --version || true' docker exec douyinweb-neko-7 supervisorctl restart google-chrome sleep 12 docker exec douyinweb-neko-7 supervisorctl status google-chrome docker exec douyinweb-neko-7 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 "jitless|js-flags|wasm"; break;; esac; done' # probe studio docker cp /tmp/neko7_cdp_probe.py douyinweb-neko-7:/tmp/neko7_cdp_probe.py docker exec -e STUDIO='{STUDIO}' douyinweb-neko-7 python3 /tmp/neko7_cdp_probe.py echo '=== traps after ===' dmesg -T 2>/dev/null | grep -i 'invalid opcode' | tail -5 docker stats douyinweb-neko-7 --no-stream --format 'mem {{{{.MemUsage}}}}' curl -sk -o /dev/null -w 'pub:%{{http_code}}\n' https://dy.nomadro.live/neko/7/ """, ) c.close() print("DONE")