douyinWEB/scripts/_fix_prod_api_startup.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

67 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
"""Hotfix: upload config.py so API can start. Does NOT touch DB."""
import paramiko
import time
import sys
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "107.173.30.245"
USER = "root"
PASSWORD = "Xiao4669805"
REPO = "/opt/douyinWEB"
LOCAL = "C:/Users/admin/Desktop/douyinWEB"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
print("upload config.py")
sftp.put(f"{LOCAL}/backend/app/config.py", f"{REPO}/backend/app/config.py")
sftp.close()
print("restart api")
c.exec_command("systemctl restart douyinweb-api >/dev/null 2>&1", timeout=5)
time.sleep(10)
_, o, _ = c.exec_command("systemctl is-active douyinweb-api", timeout=15)
print("api:", o.read().decode().strip())
_, o, _ = c.exec_command(
"curl -sS -m 8 http://127.0.0.1:8014/api/health 2>&1 | head -c 600",
timeout=20,
)
print("health:", o.read().decode("utf-8", "replace"))
_, o, _ = c.exec_command(
r"""python3 - <<'PY'
import urllib.request, json
for path in ['/api/shorts/channels','/api/yt-long/channels','/api/rooms?limit=1']:
try:
with urllib.request.urlopen('http://127.0.0.1:8014'+path, timeout=8) as r:
data=json.loads(r.read().decode())
if 'channels' in data:
print(path, 'channels=', len(data.get('channels') or []))
elif 'items' in data:
print(path, 'items=', len(data.get('items') or []), 'total=', data.get('total'))
elif 'rooms' in data:
print(path, 'rooms=', len(data.get('rooms') or []), 'total=', data.get('total'))
else:
print(path, 'keys=', list(data.keys())[:8])
except Exception as e:
print(path, 'ERR', e)
PY""",
timeout=30,
)
print(o.read().decode("utf-8", "replace"))
_, o, _ = c.exec_command(
"journalctl -u douyinweb-api -n 15 --no-pager -o cat 2>/dev/null | tail -15",
timeout=20,
)
print("journal:\n", o.read().decode("utf-8", "replace")[-1500:])
c.close()
print("DONE")