feat: add SSH connectivity check

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-21 12:25:16 +08:00
parent 522fa1b57e
commit 005be7b31c
2 changed files with 69 additions and 0 deletions

24
src/autossh_mgr/check.py Normal file
View File

@@ -0,0 +1,24 @@
import os
import subprocess
from autossh_mgr.config import TunnelConfig
def build_ssh_check_cmd(tunnel: TunnelConfig) -> list[str]:
return [
"ssh",
"-o", "BatchMode=yes",
"-o", "ConnectTimeout=5",
"-i", os.path.expanduser(tunnel.identity_file),
"-p", str(tunnel.port),
f"{tunnel.user}@{tunnel.host}",
"true",
]
def check_connectivity(tunnel: TunnelConfig) -> tuple[bool, str]:
result = subprocess.run(
build_ssh_check_cmd(tunnel),
capture_output=True,
text=True,
)
return result.returncode == 0, result.stderr.strip()