# -*- coding: utf-8 -*- from __future__ import annotations import sys import time import httpx import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") def ssh(port=4014, user="eric", password="4669805"): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(6): try: c.connect("107.173.30.245", port, user, password, timeout=45, banner_timeout=90, allow_agent=False, look_for_keys=False) return c except Exception as ex: print("ssh", i, type(ex).__name__, flush=True) time.sleep(2) raise RuntimeError("ssh") def run(c, cmd, timeout=60): _, o, e = c.exec_command(cmd, timeout=timeout) return (o.read() + e.read()).decode("utf-8", "replace") g = ssh() print("=== unit file ===", flush=True) print(run(g, "echo '4669805' | sudo -S -p '' cat /etc/systemd/system/douyinweb-api.service"), flush=True) print("=== status/journal ===", flush=True) print( run( g, "echo '4669805' | sudo -S -p '' bash -c '" "systemctl status douyinweb-api --no-pager -l | head -30; " "journalctl -u douyinweb-api -n 40 --no-pager'" ), flush=True, ) print("=== force start ===", flush=True) print( run( g, "echo '4669805' | sudo -S -p '' bash -c '" "systemctl daemon-reload; " "systemctl reset-failed douyinweb-api; " "systemctl kill -s SIGKILL douyinweb-api || true; " "sleep 1; " "systemctl start douyinweb-api; " "sleep 4; " "systemctl is-active douyinweb-api; " "ss -lntp | grep 8014 || true; " "curl -sS -m 5 -o /dev/null -w health:%{http_code}\\\\n http://127.0.0.1:8014/api/health || true'" ), flush=True, ) g.close()