douyinWEB/scripts/_rescue_vps_api.py
2026-09-13 22:10:49 -05:00

43 lines
1.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def main() -> None:
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)
sftp = c.open_sftp()
with sftp.file("/tmp/_rescue_api.sh", "w") as f:
f.write(
r"""#!/bin/bash
systemctl status douyinweb-api --no-pager | head -30
echo '---KILL---'
systemctl kill -s SIGKILL douyinweb-api 2>/dev/null || true
sleep 1
systemctl reset-failed douyinweb-api || true
systemctl start douyinweb-api
sleep 4
systemctl is-active douyinweb-api
curl -sS -m 5 -o /dev/null -w 'health=%{http_code}\n' http://127.0.0.1:8014/api/health || true
echo '---YT SVC---'
systemctl list-units --type=service --all | grep -iE 'youtube|yt-svc|innertube' || true
docker ps --format '{{.Names}} {{.Ports}}' | head -40
ss -lntp | grep -E '8089|8099|8014' || true
"""
)
sftp.close()
_, o, e = c.exec_command("bash /tmp/_rescue_api.sh", timeout=60)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
if __name__ == "__main__":
main()