69 lines
2.3 KiB
Bash
Executable File
69 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# Auto System Health Check - Exécuté toutes les 5 minutes
|
|
LOG_FILE="/var/log/wevads_auto_health.log"
|
|
echo "========================================" >> $LOG_FILE
|
|
echo "Auto Health Check - $(date)" >> $LOG_FILE
|
|
echo "========================================" >> $LOG_FILE
|
|
|
|
# 1. Vérifier et créer fichiers JS manquants
|
|
echo "[1] Checking JS files..." >> $LOG_FILE
|
|
JS_DIR="/opt/wevads/public/js"
|
|
mkdir -p $JS_DIR
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# 2. Exécuter nettoyage DB
|
|
echo "[2] Running DB cleanup..." >> $LOG_FILE
|
|
sudo -u postgres psql -d adx_system -c "SELECT admin.auto_full_cleanup();" >> $LOG_FILE 2>&1
|
|
|
|
# 3. Vérifier VMTAs manquants
|
|
echo "[3] Checking missing VMTAs..." >> $LOG_FILE
|
|
sudo -u postgres psql -d adx_system -c "SELECT admin.auto_check_missing_vmtas();" >> $LOG_FILE 2>&1
|
|
|
|
# 4. Update quotas cloud
|
|
echo "[4] Updating cloud quotas..." >> $LOG_FILE
|
|
sudo -u postgres psql -d adx_system -c "SELECT admin.auto_update_cloud_quotas();" >> $LOG_FILE 2>&1
|
|
|
|
# 5. Vérifier services critiques
|
|
echo "[5] Checking critical services..." >> $LOG_FILE
|
|
|
|
# Apache/Nginx
|
|
if systemctl is-active --quiet apache2; then
|
|
echo "✅ Apache running" >> $LOG_FILE
|
|
elif systemctl is-active --quiet nginx; then
|
|
echo "✅ Nginx running" >> $LOG_FILE
|
|
else
|
|
echo "⚠️ Web server not running, attempting restart..." >> $LOG_FILE
|
|
systemctl restart apache2 2>/dev/null || systemctl restart nginx 2>/dev/null
|
|
fi
|
|
|
|
# PostgreSQL
|
|
if systemctl is-active --quiet postgresql; then
|
|
echo "✅ PostgreSQL running" >> $LOG_FILE
|
|
else
|
|
echo "❌ PostgreSQL down!" >> $LOG_FILE
|
|
fi
|
|
|
|
# n8n
|
|
if pgrep -f "n8n" > /dev/null; then
|
|
echo "✅ n8n running" >> $LOG_FILE
|
|
else
|
|
echo "⚠️ n8n not running, attempting restart..." >> $LOG_FILE
|
|
nohup n8n start > /var/log/n8n.log 2>&1 &
|
|
fi
|
|
|
|
# 6. Stats finales
|
|
echo "[6] System stats:" >> $LOG_FILE
|
|
SERVERS=$(sudo -u postgres psql -d adx_system -t -c "SELECT COUNT(*) FROM admin.servers WHERE status IN ('active','running');" | tr -d ' ')
|
|
VMTAS=$(sudo -u postgres psql -d adx_system -t -c "SELECT COUNT(*) FROM admin.vmtas;" | tr -d ' ')
|
|
ALERTS=$(sudo -u postgres psql -d adx_system -t -c "SELECT COUNT(*) FROM admin.cloud_alerts WHERE status='active';" | tr -d ' ')
|
|
|
|
echo "Serveurs actifs: $SERVERS" >> $LOG_FILE
|
|
echo "VMTAs: $VMTAS" >> $LOG_FILE
|
|
echo "Alertes actives: $ALERTS" >> $LOG_FILE
|
|
|
|
echo "✅ Health check completed" >> $LOG_FILE
|
|
echo "" >> $LOG_FILE
|