111 lines
3.9 KiB
Python
111 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Deploy Chrome SIGILL/Aw Snap auto-heal + run heal NOW on dy (and dylive)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PASS = "Xiao4669805"
|
|
HOSTS = [("dy", "108.174.50.68"), ("dylive", "107.173.30.245")]
|
|
FILES = [
|
|
("backend/app/youtube_neko.py", "/opt/douyinWEB/backend/app/youtube_neko.py"),
|
|
("backend/neko/browser-launch.sh", "/opt/douyinWEB/backend/neko/browser-launch.sh"),
|
|
("scripts/linux/neko_health_watch.sh", "/opt/douyinWEB/scripts/linux/neko_health_watch.sh"),
|
|
]
|
|
|
|
REMOTE = r'''#!/bin/bash
|
|
set -euo pipefail
|
|
chmod +x /opt/douyinWEB/backend/neko/browser-launch.sh || true
|
|
install -m 755 /opt/douyinWEB/scripts/linux/neko_health_watch.sh /usr/local/bin/neko_health_watch.sh 2>/dev/null || true
|
|
# Ensure watch timer/service picks up new script if unit exists (no config rewrite).
|
|
systemctl restart douyinweb-neko-watch.service 2>/dev/null || systemctl restart neko-health-watch.service 2>/dev/null || true
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python - <<'PY'
|
|
from app.youtube_neko import (
|
|
heal_neko_runtime,
|
|
_chrome_tab_crash_reason,
|
|
_chrome_renderer_probe,
|
|
_devtools_version_ok,
|
|
_restart_chrome_in_container,
|
|
_cdp_nudge_live_studio_tab,
|
|
)
|
|
import json, time
|
|
print("pre_probe8", _chrome_renderer_probe(8))
|
|
print("pre_crash8", _chrome_tab_crash_reason(8))
|
|
print("pre_cdp8", _devtools_version_ok(8))
|
|
# If still wedged, force Chrome soft-restart NOW (do not wait for loop).
|
|
reason = _chrome_tab_crash_reason(8) or _chrome_renderer_probe(8)
|
|
if reason:
|
|
print("FORCE_RESTART8", reason)
|
|
print("restart", _restart_chrome_in_container(8))
|
|
time.sleep(5)
|
|
print("nudge", _cdp_nudge_live_studio_tab(8))
|
|
print("HEAL_NOW", json.dumps(heal_neko_runtime(), ensure_ascii=False)[:2000])
|
|
time.sleep(3)
|
|
print("post_probe8", _chrome_renderer_probe(8))
|
|
print("post_crash8", _chrome_tab_crash_reason(8))
|
|
print("post_cdp8", _devtools_version_ok(8))
|
|
PY
|
|
systemctl restart douyinweb-api
|
|
for i in $(seq 1 20); do
|
|
c=$(curl -sS -m 3 -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health || echo x)
|
|
echo health_$i=$c
|
|
[ "$c" = "200" ] && break
|
|
sleep 2
|
|
done
|
|
.venv/bin/python - <<'PY'
|
|
from app.youtube_neko import heal_neko_runtime, _chrome_renderer_probe
|
|
import json
|
|
print("HEAL_AFTER_API", json.dumps(heal_neko_runtime(), ensure_ascii=False)[:1500])
|
|
print("final_probe8", _chrome_renderer_probe(8))
|
|
PY
|
|
systemctl is-active douyinweb-api
|
|
'''
|
|
|
|
|
|
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", PASS, timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=90)
|
|
return c
|
|
except Exception as e:
|
|
print(f"ssh_retry {host} {i}: {e}", flush=True)
|
|
time.sleep(2 + i)
|
|
raise SystemExit(f"ssh_fail {host}")
|
|
|
|
|
|
def deploy(label: str, host: str):
|
|
print(f"\n===== {label} {host} =====", flush=True)
|
|
c = connect(host)
|
|
sftp = c.open_sftp()
|
|
for rel, dst in FILES:
|
|
data = (ROOT / rel).read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
|
tmp = f"/tmp/_sigill_{Path(rel).name}"
|
|
with sftp.file(tmp, "wb") as f:
|
|
f.write(data)
|
|
_, o, e = c.exec_command(f"mkdir -p $(dirname {dst}); cat {tmp} > {dst} && echo OK {dst}", timeout=30)
|
|
print((o.read() + e.read()).decode()[:200], flush=True)
|
|
with sftp.file("/tmp/_deploy_sigill_autoheal.sh", "w") as f:
|
|
f.write(REMOTE.replace("\r\n", "\n"))
|
|
sftp.close()
|
|
_, o, e = c.exec_command("bash /tmp/_deploy_sigill_autoheal.sh", timeout=300)
|
|
print((o.read() + e.read()).decode("utf-8", "replace")[-6000:], flush=True)
|
|
c.close()
|
|
|
|
|
|
def main():
|
|
for label, host in HOSTS:
|
|
deploy(label, host)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|