70 lines
2.6 KiB
Python
70 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Post-deploy verify + tiktok optimistic toggle FE."""
|
|
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")]
|
|
LOCAL_TT = ROOT / "frontend" / "src" / "app" / "tiktok" / "page.tsx"
|
|
|
|
VERIFY = r'''
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python <<'PY'
|
|
from app.youtube_neko import heal_crashed_assign_nekos, _neko_ids_needed_for_live, _container_state
|
|
from app.yt_long_db import list_pending_yt_long_jobs
|
|
from app.youtube_relay_pipeline import youtube_relay_pipeline
|
|
import json
|
|
print("needed", sorted(_neko_ids_needed_for_live()))
|
|
print("heal", json.dumps(heal_crashed_assign_nekos(), ensure_ascii=False)[:500])
|
|
pend = list_pending_yt_long_jobs(limit=8)
|
|
empty = sum(1 for j in pend if not str(j.get("channel_pk") or "").strip())
|
|
print("pending", len(pend), "empty_channel", empty)
|
|
st = youtube_relay_pipeline.status()
|
|
print("relay_pushing", st.get("pushing_count"), "running", st.get("running"))
|
|
for nid in sorted(_neko_ids_needed_for_live())[:5]:
|
|
s = _container_state(nid)
|
|
print("neko", nid, "run", s.get("running"), "oom", s.get("oom_killed"), "st", s.get("status"))
|
|
PY
|
|
curl -sS -m 5 -o /dev/null -w 'health:%{http_code}\n' http://127.0.0.1:8014/api/health
|
|
'''
|
|
|
|
|
|
def connect(host: str):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
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 run(c, cmd, t=120):
|
|
_, o, e = c.exec_command(cmd, timeout=t)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
for label, host in HOSTS:
|
|
print(f"\n===== {label} {host} =====", flush=True)
|
|
c = connect(host)
|
|
sftp = c.open_sftp()
|
|
data = LOCAL_TT.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
|
with sftp.file("/tmp/_tiktok_page.tsx", "wb") as f:
|
|
f.write(data)
|
|
sftp.close()
|
|
print(run(c, "cat /tmp/_tiktok_page.tsx > /opt/douyinWEB/frontend/src/app/tiktok/page.tsx && echo TT_OK", 20), flush=True)
|
|
print(run(c, "cd /opt/douyinWEB/frontend && npm run build 2>&1 | tail -8; systemctl restart douyinweb-web; sleep 2; systemctl is-active douyinweb-web", 400), flush=True)
|
|
print(run(c, VERIFY, 90), flush=True)
|
|
c.close()
|