addon
This commit is contained in:
116
docs/FIX_DEBUG_PAYLOAD.md
Executable file
116
docs/FIX_DEBUG_PAYLOAD.md
Executable file
@@ -0,0 +1,116 @@
|
||||
# Fix: Script bench.sh bloqué en mode non-interactif
|
||||
|
||||
## Problème
|
||||
|
||||
Lorsque le script `bench.sh` était exécuté via curl pipe bash :
|
||||
|
||||
```bash
|
||||
curl -fsSL http://10.0.0.50:8087/scripts/bench.sh | sudo bash -s -- ...
|
||||
```
|
||||
|
||||
Le script s'arrêtait après l'affichage du payload JSON et ne continuait pas l'envoi au serveur.
|
||||
|
||||
## Cause Racine
|
||||
|
||||
1. **DEBUG_PAYLOAD activé par défaut** (ligne 37) :
|
||||
```bash
|
||||
DEBUG_PAYLOAD="${DEBUG_PAYLOAD:-1}" # Par défaut: 1 (activé)
|
||||
```
|
||||
|
||||
2. **Attente input interactive** (ligne 1493) :
|
||||
```bash
|
||||
read -p "Appuyez sur Entrée pour continuer l'envoi ou Ctrl+C pour annuler..."
|
||||
```
|
||||
|
||||
3. **Pas de TTY en mode pipe** : Quand le script est exécuté via `curl | bash`, il n'y a pas de terminal interactif (`stdin` n'est pas un TTY), donc le `read -p` bloque indéfiniment en attendant un input qui ne viendra jamais.
|
||||
|
||||
## Solution Implémentée
|
||||
|
||||
### 1. Désactiver DEBUG_PAYLOAD par défaut
|
||||
|
||||
```bash
|
||||
# Avant
|
||||
DEBUG_PAYLOAD="${DEBUG_PAYLOAD:-1}" # Par défaut: 1 (activé)
|
||||
|
||||
# Après
|
||||
DEBUG_PAYLOAD="${DEBUG_PAYLOAD:-0}" # Par défaut: 0 (désactivé)
|
||||
```
|
||||
|
||||
### 2. Détection du mode interactif
|
||||
|
||||
Ajout d'un test `[[ -t 0 ]]` pour vérifier si stdin est un terminal :
|
||||
|
||||
```bash
|
||||
# Demander confirmation seulement si on a un terminal interactif
|
||||
if [[ -t 0 ]]; then
|
||||
read -p "Appuyez sur Entrée pour continuer l'envoi ou Ctrl+C pour annuler..."
|
||||
else
|
||||
log_warn "Mode non-interactif détecté - envoi automatique dans 2 secondes..."
|
||||
sleep 2
|
||||
fi
|
||||
```
|
||||
|
||||
## Comportement Après Fix
|
||||
|
||||
### Mode Normal (via curl pipe)
|
||||
```bash
|
||||
curl -fsSL http://10.0.0.50:8087/scripts/bench.sh | sudo bash -s -- \
|
||||
--server http://10.0.0.50:8007 \
|
||||
--token "..." \
|
||||
--iperf-server 10.0.0.50
|
||||
```
|
||||
- DEBUG_PAYLOAD = 0 (pas d'affichage du payload)
|
||||
- Envoi automatique au serveur
|
||||
- ✅ **Fonctionne correctement**
|
||||
|
||||
### Mode Debug Local
|
||||
```bash
|
||||
sudo DEBUG_PAYLOAD=1 bash scripts/bench.sh
|
||||
```
|
||||
- Affiche le payload complet
|
||||
- Sauvegarde dans `/tmp/bench_payload_YYYYMMDD_HHMMSS.json`
|
||||
- Demande confirmation avant envoi (mode interactif détecté)
|
||||
|
||||
### Mode Debug via Curl
|
||||
```bash
|
||||
curl -fsSL http://10.0.0.50:8087/scripts/bench.sh | DEBUG_PAYLOAD=1 sudo bash -s -- ...
|
||||
```
|
||||
- Affiche le payload complet
|
||||
- Sauvegarde dans `/tmp/bench_payload_YYYYMMDD_HHMMSS.json`
|
||||
- Message : "Mode non-interactif détecté - envoi automatique dans 2 secondes..."
|
||||
- Envoi après 2 secondes
|
||||
- ✅ **Fonctionne correctement**
|
||||
|
||||
## Test de Validation
|
||||
|
||||
```bash
|
||||
# Test 1 : Mode normal (doit envoyer au serveur)
|
||||
curl -fsSL http://10.0.0.50:8087/scripts/bench.sh | sudo bash -s -- \
|
||||
--server http://10.0.0.50:8007 \
|
||||
--token "29855796dacf5cfe75ff9b02d6adf3dd0f9c52db5b53e7abfb4c0df7ece1be0a" \
|
||||
--iperf-server 10.0.0.50
|
||||
|
||||
# Test 2 : Mode debug local (doit demander confirmation)
|
||||
cd /home/gilles/Documents/vscode/serv_benchmark
|
||||
sudo DEBUG_PAYLOAD=1 bash scripts/bench.sh
|
||||
|
||||
# Test 3 : Mode debug via curl (doit envoyer après 2s)
|
||||
curl -fsSL http://10.0.0.50:8087/scripts/bench.sh | DEBUG_PAYLOAD=1 sudo bash -s -- \
|
||||
--server http://10.0.0.50:8007 \
|
||||
--token "29855796dacf5cfe75ff9b02d6adf3dd0f9c52db5b53e7abfb4c0df7ece1be0a" \
|
||||
--iperf-server 10.0.0.50
|
||||
```
|
||||
|
||||
## Fichiers Modifiés
|
||||
|
||||
- `scripts/bench.sh` (lignes 37 et 1493-1499)
|
||||
|
||||
## Statut
|
||||
|
||||
✅ **CORRIGÉ** - Le script s'exécute maintenant correctement en mode non-interactif et envoie le payload au serveur.
|
||||
|
||||
---
|
||||
|
||||
**Date**: 2025-12-18
|
||||
**Issue**: Script bloqué en mode curl pipe bash
|
||||
**Root Cause**: DEBUG_PAYLOAD=1 par défaut + read -p sans détection TTY
|
||||
Reference in New Issue
Block a user