Files
wevads-platform/scripts/auto_heal.sh
2026-02-26 04:53:11 +01:00

26 lines
850 B
Bash
Executable File

#!/bin/bash
# Auto-heal services - Run every 5 minutes
# Checks and restarts critical services if down
LOG_FILE="/opt/wevads/logs/auto_heal.log"
API_URL="http://127.0.0.1:5821/api/system-health-api.php"
echo "[$(date)] Starting auto-heal check..." >> $LOG_FILE
# Check and heal
RESULT=$(curl -s -X POST "$API_URL" -d "action=auto_heal")
# Log result
echo "[$(date)] Result: $RESULT" >> $LOG_FILE
# If critical failures, send alert
if echo "$RESULT" | grep -q '"failed":\['; then
FAILED=$(echo "$RESULT" | jq -r '.failed[]' 2>/dev/null)
if [ ! -z "$FAILED" ]; then
# Send Telegram alert
TELEGRAM_BOT="7605775322"
TELEGRAM_MSG="🚨 CRITICAL: Services failed to restart: $FAILED"
curl -s "https://api.telegram.org/bot$TELEGRAM_BOT/sendMessage?chat_id=$TELEGRAM_BOT&text=$TELEGRAM_MSG" > /dev/null
fi
fi