diff --git a/ops-scripts/opus-intents/wevia-self-repair.sh b/ops-scripts/opus-intents/wevia-self-repair.sh new file mode 100755 index 000000000..6d1508041 --- /dev/null +++ b/ops-scripts/opus-intents/wevia-self-repair.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# WEVIA SELF-REPAIR - tourne en cron, répare les warns toute seule +# Appelle les endpoints auto-fix déjà présents dans WEVIA, zero nouveau code +LOG=/var/log/wevia-self-repair.log +TS=$(date -Iseconds) + +# 1. Paperclip stuck tasks → call paperclip-unfreeze via master-api (internal) +PP_STUCK=$(curl -sk -m5 "http://127.0.0.1/api/paperclip-status.php" -H "Host: weval-consulting.com" 2>/dev/null | grep -oE '"failed":[0-9]+' | head -1) +if echo "$PP_STUCK" | grep -qE '"failed":[1-9]'; then + echo "[$TS] Paperclip fail detected: $PP_STUCK → calling unfreeze" >> $LOG + # Call master-api with internal token for paperclip_unfreeze intent + curl -sk -m20 -X POST "http://127.0.0.1/api/wevia-master-api.php" \ + -H "Host: weval-consulting.com" \ + -H "Content-Type: application/json" \ + -H "X-Agent-Token: mAN8ba3zDlcYW62dJS3ltUCwzoRqkOLbQrf0aBKsTPo" \ + -d '{"message":"paperclip_unfreeze"}' >> $LOG 2>&1 +fi + +# 2. CDP chromes offline → relance via launch script existant +CDP_RUNNING=$(curl -sk -m5 "http://127.0.0.1/api/cdp-status.php" -H "Host: weval-consulting.com" 2>/dev/null | grep -oE '"running":[0-9]+' | head -1 | grep -oE '[0-9]+') +if [ "${CDP_RUNNING:-0}" -lt 1 ]; then + echo "[$TS] CDP 0 running → launching 8 chromes" >> $LOG + nohup bash /opt/weval-ops/opus-intents/launch-chromes-all.sh > /dev/null 2>&1 & +fi + +# 3. V83 orchestrator health check (détecte si crash 502) +V83=$(curl -sk -m8 "http://127.0.0.1/api/wevia-v83-multi-agent-orchestrator.php?action=match&q=health" -H "Host: weval-consulting.com" -o /dev/null -w "%{http_code}" 2>/dev/null) +if [ "$V83" != "200" ]; then + echo "[$TS] V83 unhealthy ($V83) → FPM reload" >> $LOG + # reload graceful (vide workers bloqués) + sudo -n systemctl reload php8.5-fpm 2>>$LOG +fi + +echo "[$TS] self-repair cycle complete" >> $LOG