#!/bin/sh # Watchdog Code Versioning — verifie le MCP Forgejo (8770), # relance via start_mcp_forgejo.sh s'il ne repond pas sur /health. # Idempotent : couvre le boot (rien ne tourne) ET le crash. # Lance par tache planifiee DSM toutes les 5 min. BASE=/volume1/homes/Master/App/Code_versioning LOG="$BASE/watchdog.log" TS=$(date '+%Y-%m-%d %H:%M:%S') wait_health() { URL="$1" TRIES="$2" i=0 while [ "$i" -lt "$TRIES" ]; do if curl -s -f -m 5 "$URL" > /dev/null 2>&1; then return 0 fi i=$((i + 1)) sleep 3 done return 1 } check_and_restart() { NAME="$1" URL="$2" STARTER="$3" if curl -s -f -m 5 "$URL" > /dev/null 2>&1; then return 0 fi echo "$TS [$NAME] KO sur $URL — relance via $STARTER" >> "$LOG" sh "$BASE/$STARTER" if wait_health "$URL" 5; then echo "$TS [$NAME] relance OK" >> "$LOG" else echo "$TS [$NAME] ECHEC relance — toujours muet apres ~15s" >> "$LOG" fi } check_and_restart "mcp-forgejo" "http://127.0.0.1:8770/health" "start_mcp_forgejo.sh"