45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Hotfix timeslot-test kick (non-blocking) on dylive API."""
|
|
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]
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
sftp.put(str(ROOT / "backend/app/youtube_relay_pipeline.py"), "/tmp/youtube_relay_pipeline.py")
|
|
sftp.close()
|
|
|
|
cmd = r"""
|
|
set -euo pipefail
|
|
install -m 0644 /tmp/youtube_relay_pipeline.py /opt/douyinWEB/backend/app/youtube_relay_pipeline.py
|
|
systemctl restart douyinweb-api
|
|
for i in $(seq 1 40); do curl -sS -m 2 http://127.0.0.1:8014/api/health >/dev/null 2>&1 && break; sleep 1; done
|
|
CS=$(mktemp)
|
|
curl -sS -m 20 -c "$CS" -b "$CS" -X POST http://127.0.0.1:8014/api/auth/login \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"username":"hackrobot","password":"Xiao4669805@"}' >/dev/null
|
|
echo -n 'next:'
|
|
curl -sS -m 45 -b "$CS" -o /tmp/next.json -w '%{http_code}' -X POST \
|
|
http://127.0.0.1:8014/api/youtube/relay/timeslot-test/next
|
|
echo
|
|
python3 -c 'import json;d=json.load(open("/tmp/next.json"));print(d.get("timeslot_test_next"), d.get("settings",{}).get("youtube_relay_timeslot_test"), d.get("settings",{}).get("youtube_relay_timeslot_test_group_id"))'
|
|
# leave test off after smoke so we do not strand operator mid-test unexpectedly
|
|
curl -sS -m 20 -b "$CS" -X POST http://127.0.0.1:8014/api/youtube/relay/timeslot-test \
|
|
-H 'Content-Type: application/json' -d '{"enabled":false}' >/dev/null
|
|
echo DONE
|
|
"""
|
|
_, o, e = c.exec_command(cmd, timeout=180)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
code = o.channel.recv_exit_status()
|
|
c.close()
|
|
raise SystemExit(code)
|