allez on essaie ca

This commit is contained in:
Gaël
2025-09-08 18:53:34 +02:00
parent a1e462eab9
commit 542aea6602
2 changed files with 41 additions and 11 deletions

View File

@@ -1,29 +1,58 @@
#!/bin/sh
set -eu
# Arrêt propre: en sh, on utilise INT/TERM (sans "SIG")
log() { printf '%s %s\n' "[$(date -u +%FT%TZ)]" "$*"; }
stop() {
echo "[stop] shutting down..."
# Tuer proprement les 2 enfants si présents
log "stopping..."
[ -n "${PID1-}" ] && kill -TERM "$PID1" 2>/dev/null || true
[ -n "${PID2-}" ] && kill -TERM "$PID2" 2>/dev/null || true
[ -n "${TPID-}" ] && kill -TERM "$TPID" 2>/dev/null || true
wait || true
exit 0
}
trap stop INT TERM
# (facultatif si tu fais un git pull ici)
# git fetch --all || true
# git reset --hard origin/main || true
cd /app
export GIT_TERMINAL_PROMPT=0
# Lancer les 2 bots en arrière-plan
python -u post_rss_to_ghost.py & PID1=$!
python -u presquegratos.py & PID2=$!
# MAJ forcée du code à chaque (re)démarrage
if [ -d .git ]; then
i=0
while [ $i -lt 5 ]; do
if git fetch --all --prune && git reset --hard origin/main; then
log "git updated to origin/main"
break
fi
i=$((i+1))
log "git update failed (attempt $i/5); retrying in 10s..."
sleep 10
done
[ $i -ge 5 ] && log "WARNING: git update failed after 5 attempts — continuing with current code"
else
log "WARNING: /app is not a git repo; skipping git update"
fi
# Attendre qu'un des deux termine; l'autre sera tué dans stop()
# /bin/sh na pas toujours wait -n, on fait un petit poll
# Dossiers logs
mkdir -p /var/log
: > /var/log/daily.log
: > /var/log/weekly.log
# Lancer les 2 bots (logs non bufferisés)
python -u post_rss_to_ghost.py > /var/log/daily.log 2>&1 & PID1=$!
python -u presquegratos.py > /var/log/weekly.log 2>&1 & PID2=$!
# Suivre les 2 fichiers de logs dans la sortie du conteneur
tail -F /var/log/daily.log /var/log/weekly.log &
TPID=$!
# Attente portable (pas de wait -n en /bin/sh)
while :; do
if ! kill -0 "$PID1" 2>/dev/null; then wait "$PID1" || true; break; fi
if ! kill -0 "$PID2" 2>/dev/null; then wait "$PID2" || true; break; fi
sleep 1
done
# Si un des scripts sort, on arrête le tail (le trap TERM arrêtera l'autre script)
kill -TERM "$TPID" 2>/dev/null || true
wait || true