63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
||
"""SSH 到板子:打印 ENABLE_NEKO 与 Docker 中与 srs/neko 相关的容器。
|
||
|
||
环境变量与 deploy_live_paramiko.py 一致:
|
||
LIVE_DEPLOY_HOST(默认 192.168.21.105)
|
||
LIVE_DEPLOY_USER(默认 live)
|
||
LIVE_DEPLOY_PASS(默认 12345678)
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import sys
|
||
|
||
try:
|
||
import paramiko
|
||
except ImportError:
|
||
print("请先执行: pip install paramiko", file=sys.stderr)
|
||
sys.exit(1)
|
||
|
||
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_SH = r"""
|
||
echo "--- ENABLE_NEKO in known env files ---"
|
||
for f in /opt/live/config/system-stack.env /opt/live/generated/system-stack.env /home/live/douyinyoutube/config/system-stack.env; do
|
||
if [ -f "$f" ]; then
|
||
echo "=== $f ==="
|
||
grep -E '^ENABLE_NEKO=' "$f" 2>/dev/null || echo '(no ENABLE_NEKO line)'
|
||
fi
|
||
done
|
||
echo "--- docker: srs / neko (running or all) ---"
|
||
docker ps -a --format '{{.Names}} {{.Status}}' 2>/dev/null | grep -iE 'neko|srs' || echo '(no container name matching neko|srs)'
|
||
echo "--- docker ps -a (first 25) ---"
|
||
docker ps -a --format '{{.Names}} {{.Status}}' 2>/dev/null | head -25
|
||
"""
|
||
|
||
|
||
def main() -> int:
|
||
c = paramiko.SSHClient()
|
||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||
try:
|
||
c.connect(HOST, username=USER, password=PASS, timeout=20)
|
||
except Exception as e:
|
||
print(f"SSH_CONNECT_FAILED {HOST} {type(e).__name__}: {e}", file=sys.stderr)
|
||
return 2
|
||
_, stdout, stderr = c.exec_command(
|
||
"export LC_ALL=C.UTF-8 LANG=C.UTF-8; " + REMOTE_SH,
|
||
timeout=90,
|
||
)
|
||
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(err, file=sys.stderr, end="")
|
||
return code
|
||
|
||
|
||
if __name__ == "__main__":
|
||
raise SystemExit(main())
|