douyinWEB/scripts/_force_restart_prod_api.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

41 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
import paramiko
import time
import sys
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd, timeout=60):
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace").strip()
print("force kill stuck api")
print(run("systemctl kill -s SIGKILL douyinweb-api; sleep 1; systemctl reset-failed douyinweb-api; systemctl start douyinweb-api"))
time.sleep(8)
print("api:", run("systemctl is-active douyinweb-api"))
print("pid:", run("systemctl show douyinweb-api -p MainPID --value"))
print("health:", run("curl -sS -m 8 http://127.0.0.1:8014/api/health"))
print(run(r"""
python3 - <<'PY'
import urllib.request, json, sqlite3
for path in ['/api/shorts/channels','/api/yt-long/channels','/api/tiktok/channels']:
try:
with urllib.request.urlopen('http://127.0.0.1:8014'+path, timeout=10) as r:
data=json.loads(r.read().decode())
print(path, 'channels=', len(data.get('channels') or []))
except Exception as e:
print(path, 'ERR', e)
conn=sqlite3.connect('file:/opt/douyinWEB/backend/data/monitor.db?mode=ro', uri=True)
for t in ['shorts_channels','yt_long_channels','rooms','tiktok_channels','shorts_jobs']:
print('db', t, conn.execute(f'select count(*) from {t}').fetchone()[0])
conn.close()
PY
"""))
print("journal last:")
print(run("journalctl -u douyinweb-api -n 20 --no-pager -o cat")[-2000:])
c.close()