Files
gitlab-instance-0a899031_do…/tools/ssh_neko_start.py
2026-03-28 16:27:42 -05:00

43 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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())