51 lines
1.4 KiB
Bash
Executable File
51 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Auto-Repair Infrastructure Script for n8n
|
|
|
|
ERRORS=0
|
|
REPAIRS=0
|
|
|
|
# Check PMTA status on all servers
|
|
check_pmta() {
|
|
for server in $(curl -s "http://localhost:5821/api/n8n-connector.php?action=servers&key=wevads-n8n-2026-secret-key" | jq -r '.servers[].main_ip'); do
|
|
if ! timeout 5 ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 root@$server "pgrep pmta" &>/dev/null; then
|
|
ERRORS=$((ERRORS+1))
|
|
# Try to restart
|
|
ssh -o StrictHostKeyChecking=no root@$server "systemctl restart pmta" &>/dev/null && REPAIRS=$((REPAIRS+1))
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Check disk space
|
|
check_disk() {
|
|
DISK_FREE=$(df / | tail -1 | awk '{print $5}' | tr -d '%')
|
|
if [ "$DISK_FREE" -gt 90 ]; then
|
|
ERRORS=$((ERRORS+1))
|
|
# Clean logs
|
|
find /var/log -name "*.log" -mtime +7 -delete 2>/dev/null && REPAIRS=$((REPAIRS+1))
|
|
fi
|
|
}
|
|
|
|
# Check Apache
|
|
check_apache() {
|
|
if ! systemctl is-active apache2 &>/dev/null; then
|
|
ERRORS=$((ERRORS+1))
|
|
systemctl restart apache2 && REPAIRS=$((REPAIRS+1))
|
|
fi
|
|
}
|
|
|
|
# Check PostgreSQL
|
|
check_postgres() {
|
|
if ! systemctl is-active postgresql &>/dev/null; then
|
|
ERRORS=$((ERRORS+1))
|
|
systemctl restart postgresql && REPAIRS=$((REPAIRS+1))
|
|
fi
|
|
}
|
|
|
|
# Run checks
|
|
check_apache
|
|
check_postgres
|
|
check_disk
|
|
|
|
# Output JSON for n8n
|
|
echo "{\"errors\": $ERRORS, \"repairs\": $REPAIRS, \"timestamp\": \"$(date -Iseconds)\"}"
|