Remove retry mechanism from SSH connections
**Motivations:** - Retries are useless, connection must work on first attempt or fail - Simplifying code by removing unnecessary retry logic - Reducing complexity and potential for multiple connection attempts **Root causes:** - Retry mechanism was adding complexity without real benefit - If SSH connection fails, retrying won't help, it should fail immediately **Correctifs:** - Removed all retry logic from ssh_exec() function - Simplified to single attempt execution - Kept socket validation and cleanup before execution - Removed retry loop and counter variables **Evolutions:** - Simpler and more straightforward SSH connection handling - Faster failure detection when connection issues occur **Pages affectées:** - deploy.sh: Simplified ssh_exec() function, removed retry mechanism
This commit is contained in:
parent
7cbb57f8c9
commit
a943ed62e2
30
deploy.sh
30
deploy.sh
@ -33,44 +33,24 @@ check_ssh_connection() {
|
|||||||
ssh -O check -o ControlPath="${SSH_CONTROL_PATH}" ${SERVER} 2>/dev/null || return 1
|
ssh -O check -o ControlPath="${SSH_CONTROL_PATH}" ${SERVER} 2>/dev/null || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fonction pour exécuter une commande SSH avec connexion persistante et gestion d'erreurs robuste
|
# Fonction pour exécuter une commande SSH avec connexion persistante
|
||||||
ssh_exec() {
|
ssh_exec() {
|
||||||
local max_retries=2
|
|
||||||
local retry_count=0
|
|
||||||
|
|
||||||
while [ $retry_count -lt $max_retries ]; do
|
|
||||||
# Nettoyer le socket s'il existe mais est invalide
|
# Nettoyer le socket s'il existe mais est invalide
|
||||||
if [ -S "${SSH_CONTROL_PATH}" ]; then
|
if [ -S "${SSH_CONTROL_PATH}" ]; then
|
||||||
if ! check_ssh_connection; then
|
if ! check_ssh_connection; then
|
||||||
# Connexion morte, nettoyer avant de réessayer
|
# Connexion morte, nettoyer avant d'exécuter
|
||||||
cleanup_dead_ssh
|
cleanup_dead_ssh
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Exécuter la commande SSH
|
# Exécuter la commande SSH (une seule tentative, pas de retry)
|
||||||
# Si le socket existe mais est invalide, SSH avec ControlMaster=auto le détectera et créera une nouvelle connexion
|
ssh -o ControlMaster=auto \
|
||||||
if ssh -o ControlMaster=auto \
|
|
||||||
-o ControlPath="${SSH_CONTROL_PATH}" \
|
-o ControlPath="${SSH_CONTROL_PATH}" \
|
||||||
-o ControlPersist=300 \
|
-o ControlPersist=300 \
|
||||||
-o ConnectTimeout=10 \
|
-o ConnectTimeout=10 \
|
||||||
-o ServerAliveInterval=60 \
|
-o ServerAliveInterval=60 \
|
||||||
-o ServerAliveCountMax=3 \
|
-o ServerAliveCountMax=3 \
|
||||||
${SERVER} "$@" 2>&1; then
|
${SERVER} "$@" 2>&1
|
||||||
return 0
|
|
||||||
else
|
|
||||||
local exit_code=$?
|
|
||||||
retry_count=$((retry_count + 1))
|
|
||||||
|
|
||||||
if [ $retry_count -lt $max_retries ]; then
|
|
||||||
# Nettoyer la connexion morte avant de réessayer
|
|
||||||
cleanup_dead_ssh
|
|
||||||
sleep 1
|
|
||||||
else
|
|
||||||
# Dernière tentative échouée, retourner le code d'erreur
|
|
||||||
return $exit_code
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Nettoyer les connexions SSH persistantes et le répertoire temporaire à la fin
|
# Nettoyer les connexions SSH persistantes et le répertoire temporaire à la fin
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user