fix: add timeout to ssh-copy-id and check_ssh_connectivity to prevent hangs
This commit is contained in:
@@ -60,7 +60,7 @@ def check_ssh_connectivity(host, user, port, key_path=None, timeout=10):
|
|||||||
|
|
||||||
identity = f"-i '{key_path}'" if key_path and os.path.isfile(key_path) else ""
|
identity = f"-i '{key_path}'" if key_path and os.path.isfile(key_path) else ""
|
||||||
cmd = f"ssh {identity} -p {port} -o ConnectTimeout={timeout} -o BatchMode=yes -o StrictHostKeyChecking=accept-new {user}@{host} 'echo migrate-ok'"
|
cmd = f"ssh {identity} -p {port} -o ConnectTimeout={timeout} -o BatchMode=yes -o StrictHostKeyChecking=accept-new {user}@{host} 'echo migrate-ok'"
|
||||||
r = run(cmd, check=False, capture=True)
|
r = run(cmd, check=False, capture=True, timeout=30)
|
||||||
if r.returncode == 0 and "migrate-ok" in r.stdout:
|
if r.returncode == 0 and "migrate-ok" in r.stdout:
|
||||||
return (True, r.stdout, r.stderr)
|
return (True, r.stdout, r.stderr)
|
||||||
return (False, r.stdout, r.stderr)
|
return (False, r.stdout, r.stderr)
|
||||||
@@ -108,7 +108,12 @@ def ssh_copy_id(host, user, port, pubkey_path):
|
|||||||
"""Копирует публичный ключ на target через ssh-copy-id или вручную."""
|
"""Копирует публичный ключ на target через ssh-copy-id или вручную."""
|
||||||
if exists("ssh-copy-id"):
|
if exists("ssh-copy-id"):
|
||||||
info("Копируем публичный ключ через ssh-copy-id ...")
|
info("Копируем публичный ключ через ssh-copy-id ...")
|
||||||
r = run(f"ssh-copy-id -p {port} -i '{pubkey_path}' {user}@{host}", check=False)
|
# Добавляем SSH опции чтобы избежать зависания
|
||||||
|
r = run(
|
||||||
|
f"ssh-copy-id -p {port} -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new -i '{pubkey_path}' {user}@{host}",
|
||||||
|
check=False,
|
||||||
|
timeout=60
|
||||||
|
)
|
||||||
if r.returncode == 0:
|
if r.returncode == 0:
|
||||||
success("Ключ добавлен на target через ssh-copy-id")
|
success("Ключ добавлен на target через ssh-copy-id")
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user