#!/bin/bash # Monitor Docker container restart counts set -euo pipefail SEND_NTFY="/usr/local/bin/send-ntfy.sh" DEBIANVM_HOST="DEBIANVM" # Get container restart counts RESTART_INFO=$(timeout 15 sshpass -p 'admin' ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@$DEBIANVM_HOST "docker ps --format '{{.Names}}:{{.Status}}' | grep -E 'Restarting|\([1-9][0-9]*\)'" 2>/dev/null || echo "") if [ -n "$RESTART_INFO" ]; then while IFS= read -r line; do CONTAINER=$(echo "$line" | cut -d':' -f1) STATUS=$(echo "$line" | cut -d':' -f2-) $SEND_NTFY warning "Container Restarting" "🟡 WARNING: Docker container '$CONTAINER' on debianvm is restarting\nStatus: $STATUS" "warning,package,arrows_counterclockwise" done <<< "$RESTART_INFO" fi logger -t docker-restart-monitor "Docker restart check completed"