#!/usr/bin/env python3 """SSH:在板子上执行 service_ctl.sh neko start(拉镜像可能较久)。""" from __future__ import annotations import os import sys import paramiko HOST = os.environ.get("LIVE_DEPLOY_HOST", "192.168.21.105") USER = os.environ.get("LIVE_DEPLOY_USER", "live") PASS = os.environ.get("LIVE_DEPLOY_PASS", "12345678") REMOTE_BASE = os.environ.get("LIVE_DEPLOY_PATH", "/home/live/douyinyoutube").rstrip("/") CMD = ( f"export LC_ALL=C.UTF-8 LANG=C.UTF-8; " f"cd {REMOTE_BASE} && bash scripts/linux/service_ctl.sh neko start" ) def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: c.connect(HOST, username=USER, password=PASS, timeout=25) except Exception as e: print(f"SSH failed: {e}", file=sys.stderr) return 2 _, stdout, stderr = c.exec_command(CMD, timeout=600) out = stdout.read().decode("utf-8", errors="replace") err = stderr.read().decode("utf-8", errors="replace") code = stdout.channel.recv_exit_status() c.close() print(out, end="") if err.strip(): print("--- stderr ---", file=sys.stderr) print(err, file=sys.stderr, end="") return code if __name__ == "__main__": raise SystemExit(main())