#!/usr/bin/env python3 import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") last = None for attempt in range(10): try: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( "107.173.30.245", 22, "root", "Xiao4669805", timeout=60, banner_timeout=180, allow_agent=False, look_for_keys=False, ) print("connected", attempt, flush=True) cmd = ( "docker ps -a --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}'; " "echo ---; " "cd /opt/douyinWEB; git rev-parse --short HEAD; " "curl -sS -m 12 -o /dev/null -w 'dylive=%{http_code}\\n' https://dylive.nomadro.com/api/health; " "systemctl is-active douyinweb-api douyinweb-web" ) _i, o, e = c.exec_command(cmd, timeout=90) print((o.read() + e.read()).decode("utf-8", "replace"), flush=True) # Start any exited containers one-by-one with timeout _i, o, e = c.exec_command( "for i in 1 2 3 4 5 6 7; do " " st=$(docker inspect -f '{{.State.Status}}' douyinweb-neko-$i 2>/dev/null || echo missing); " " echo neko-$i=$st; " " if [ \"$st\" = exited ] || [ \"$st\" = created ]; then " " timeout 45 docker start douyinweb-neko-$i && echo started_$i || echo fail_$i; " " fi; " "done; " "docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}'", timeout=420, ) print((o.read() + e.read()).decode("utf-8", "replace"), flush=True) c.close() raise SystemExit(0) except SystemExit: raise except Exception as ex: last = ex print("retry", attempt, type(ex).__name__, ex, flush=True) time.sleep(10) raise SystemExit(f"ssh failed: {last}")