66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Deploy timeslot sticky-rotate fix to VPS API only (restart uvicorn)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
LOCAL = Path(__file__).resolve().parents[1] / "backend" / "app" / "youtube_relay_pipeline.py"
|
|
REMOTE = "/opt/douyinWEB/backend/app/youtube_relay_pipeline.py"
|
|
|
|
|
|
def main() -> None:
|
|
data = LOCAL.read_bytes()
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=25, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
# backup
|
|
try:
|
|
sftp.rename(REMOTE, REMOTE + ".bak_sticky_rotate")
|
|
except OSError:
|
|
pass
|
|
with sftp.file(REMOTE, "wb") as f:
|
|
f.write(data)
|
|
sftp.close()
|
|
_, o, e = c.exec_command(
|
|
"systemctl restart douyinweb-api && sleep 2 && systemctl is-active douyinweb-api && "
|
|
"curl -sS -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health || "
|
|
"curl -sS -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/health || echo nohealth",
|
|
timeout=60,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
# wait one relay tick then show state
|
|
_, o2, e2 = c.exec_command(
|
|
r"""
|
|
sleep 8
|
|
/opt/douyinWEB/backend/.venv/bin/python - <<'PY'
|
|
import json, sqlite3, time
|
|
con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
|
|
con.row_factory=sqlite3.Row
|
|
gid='3fb8cbf7-2180-45bc-99f0-836169f0bf97'
|
|
r=dict(con.execute('select status,error,source_url,source_room_id,anchor_name,ffmpeg_pid,recent_log,updated_at from yt_relay_states where group_id=?',(gid,)).fetchone() or {})
|
|
print('status', r.get('status'), 'pid', r.get('ffmpeg_pid'), 'room', r.get('source_room_id'), 'anchor', r.get('anchor_name'))
|
|
print('url', r.get('source_url'))
|
|
print('err', (r.get('error') or '')[:120])
|
|
log=r.get('recent_log') or ''
|
|
try: lines=json.loads(log) if str(log).startswith('[') else str(log).splitlines()
|
|
except: lines=[]
|
|
for ln in lines[-12:]:
|
|
print(ln)
|
|
PY
|
|
""",
|
|
timeout=40,
|
|
)
|
|
print((o2.read() + e2.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|