Added system watchdog. and way to many other changes

This commit is contained in:
2026-04-10 18:11:16 -04:00
parent 6cc26c8fb9
commit b7706f4ab4
8 changed files with 1532 additions and 229 deletions
+11 -23
View File
@@ -22,7 +22,6 @@ parse_args "$@"
echo ""
echo "━━━ $ICON_GEAR Setup ━━━"
# ROOT CHECK
if [[ "$EUID" -ne 0 ]]; then
error "Must be run as root"
exit 1
@@ -30,10 +29,9 @@ fi
success "Running as root"
# Verify Docker is available
if ! command -v docker &>/dev/null; then
error "Docker command not found — check PATH or Docker installation"
notify "Docker daily restart failed — Docker not found on $(hostname)" "Docker Daily Restart" "alert"
notify "Docker daily restart failed — Docker not found on $(hostname)" "Docker Daily Restart" "warning"
exit 1
fi
@@ -60,9 +58,6 @@ fi
# FUNCTIONS
# -----------------------------------------------------------------------------------------------
# Attempts a docker command up to RETRY_COUNT times with SLEEP seconds between attempts.
# Returns 0 on success, 1 if all attempts fail.
# Usage: retry_docker docker restart Emby
retry_docker() {
local attempt=1
@@ -84,7 +79,7 @@ retry_docker() {
}
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_CONTAINERS $ICON_STOP $ICON_START Daily Restart ━━━
# ━━━ $ICON_CONTAINERS Daily Restart ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_CONTAINERS Daily Restart — $(date '+%Y-%m-%d %H:%M:%S') ━━━"
@@ -100,7 +95,6 @@ STARTED=()
for container in "${DAILY_RESTART_CONTAINERS[@]}"; do
echo "━━━ $ICON_CONTAINERS $container ━━━"
# Verify container exists
if ! docker inspect "$container" &>/dev/null; then
error "$container does not exist — skipping"
FAILED+=("$container")
@@ -121,7 +115,8 @@ for container in "${DAILY_RESTART_CONTAINERS[@]}"; do
echo "$ICON_STARTED $container restarted"
RESTARTED+=("$container")
else
error "Failed to restart $container"
error "Failed to restart $container after $RETRY_COUNT attempts"
notify "$container failed to restart on $(hostname)" "Docker Daily Restart" "warning"
FAILED+=("$container")
fi
fi
@@ -136,7 +131,8 @@ for container in "${DAILY_RESTART_CONTAINERS[@]}"; do
echo "$ICON_STARTED $container started"
STARTED+=("$container")
else
error "Failed to start $container"
error "Failed to start $container after $RETRY_COUNT attempts"
notify "$container failed to start on $(hostname)" "Docker Daily Restart" "warning"
FAILED+=("$container")
fi
fi
@@ -157,27 +153,19 @@ END=$(date +%s)
# -----------------------------------------------------------------------------------------------
echo "━━━━━ $ICON_SUMMARY DAILY RESTART SUMMARY ━━━━━"
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
if [[ ${#RESTARTED[@]} -gt 0 ]]; then
echo "$ICON_STARTED Restarted: ${RESTARTED[*]}"
fi
if [[ ${#STARTED[@]} -gt 0 ]]; then
echo "$ICON_STARTED Started: ${STARTED[*]}"
fi
if [[ ${#FAILED[@]} -gt 0 ]]; then
echo "$ICON_ERROR Failed: ${FAILED[*]}"
fi
[[ ${#RESTARTED[@]} -gt 0 ]] && echo "$ICON_STARTED Restarted: ${RESTARTED[*]}"
[[ ${#STARTED[@]} -gt 0 ]] && echo "$ICON_STARTED Started: ${STARTED[*]}"
[[ ${#FAILED[@]} -gt 0 ]] && echo "$ICON_ERROR Failed: ${FAILED[*]}"
if [[ "$DRY_RUN" == true ]]; then
echo "$ICON_WARN Status: DRY RUN — no changes made"
elif [[ ${#FAILED[@]} -eq 0 ]]; then
echo "$ICON_DONE Status: $ICON_SUCCESS ALL DONE"
notify "Daily restart complete — ${#RESTARTED[@]} restarted, ${#STARTED[@]} started" "Docker Daily Restart" "normal"
notify "Daily restart complete — ${#RESTARTED[@]} restarted, ${#STARTED[@]} started on $(hostname)" "Docker Daily Restart" "normal"
else
echo "$ICON_ERROR Status: $ICON_ERROR ${#FAILED[@]} container(s) failed"
notify "Daily restart completed with errors — failed: ${FAILED[*]}" "Docker Daily Restart" "alert"
notify "Daily restart completed with errors on $(hostname) — failed: ${FAILED[*]}" "Docker Daily Restart" "warning"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
[[ ${#FAILED[@]} -gt 0 ]] && exit 1