#!/bin/sh set -eu log() { printf '%s %s\n' "[$(date -u +%FT%TZ)]" "$*"; } stop() { 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 cd /app export GIT_TERMINAL_PROMPT=0 # 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 # 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