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

89 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Ops: remount browser-launch on dylive neko-6 + check dy API. Never recreate."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def connect(host: str):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(10):
try:
c.connect(
host,
22,
"root",
"Xiao4669805",
timeout=60,
allow_agent=False,
look_for_keys=False,
banner_timeout=300,
)
return c
except Exception as e:
print("retry", host, i, e, flush=True)
time.sleep(2 + i)
raise SystemExit(f"ssh_fail {host}")
# --- dylive: remount browser-launch via container restart (volumes keep profile) ---
print("=== dylive neko-6 remount ===", flush=True)
dl = connect("107.173.30.245")
_i, o, e = dl.exec_command(
r"""
set +e
NAME=douyinweb-neko-6
# ensure host launch script is LF + jitless
sed -i 's/\r$//' /opt/douyinWEB/backend/neko/browser-launch.sh
grep -n jitless /opt/douyinWEB/backend/neko/browser-launch.sh | head -1
# restart remounts binds (NOT recreate)
docker restart "$NAME"
sleep 12
docker exec "$NAME" sh -c 'cat /proc/self/mountinfo | grep browser-launch'
del=$(docker exec "$NAME" sh -c 'cat /proc/self/mountinfo | grep browser-launch' | grep -c '//deleted' || true)
echo deleted_mount=$del
docker exec "$NAME" supervisorctl status
docker exec "$NAME" sh -c 'curl -sS -m 5 http://127.0.0.1:9222/json/version | head -c 180; echo'
# if chrome fatal, start again
st=$(docker exec "$NAME" supervisorctl status google-chrome 2>/dev/null)
echo "$st"
case "$st" in
*FATAL*|*STOPPED*)
docker exec "$NAME" sh -c 'rm -f /home/neko/.config/google-chrome/Singleton*; supervisorctl start google-chrome; sleep 8; supervisorctl status google-chrome; curl -sS -m 5 http://127.0.0.1:9222/json/version | head -c 120; echo'
;;
esac
free -m | head -2
echo DYLIVE_OK
""",
timeout=180,
)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
dl.close()
# --- dy: API hang diagnose ---
print("=== dy API diagnose ===", flush=True)
dy = connect("108.174.50.68")
_i, o, e = dy.exec_command(
r"""
set +e
systemctl is-active douyinweb-api douyinweb-web
free -m | head -2
ss -lntp | grep -E ':8014|:4015' || true
timeout 5 curl -sS -m 4 -o /dev/null -w 'health:%{http_code} time:%{time_total}\n' http://127.0.0.1:8014/api/health || echo health_timeout
journalctl -u douyinweb-api -n 40 --no-pager 2>/dev/null | tail -40
# if hung workers, show top
ps aux --sort=-%mem | head -15
echo DY_OK
""",
timeout=90,
)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
dy.close()
print("DONE", flush=True)