From bfea98db6153f5412d5966225bc8e0804d259a32 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 22 Mar 2026 17:40:57 +0000 Subject: [PATCH] Don't start unhealthy --- src/healthcheck.sh | 15 +++++++++++++-- src/schedule.sh | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/healthcheck.sh b/src/healthcheck.sh index 255ba29..c4cb69d 100755 --- a/src/healthcheck.sh +++ b/src/healthcheck.sh @@ -2,15 +2,26 @@ set -e +MAX_BACKUP_AGE_SECONDS="${MAX_BACKUP_AGE_SECONDS:-86400}" + if [ -f /health/backup_completion_time.log ]; then current_time=$(date +%s) backup_time=$(date --file /health/backup_completion_time.log +%s) age_in_seconds=$((current_time - backup_time)) - - if [ ${age_in_seconds} -lt "${MAX_BACKUP_AGE_SECONDS}" ]; then + + if [ "${age_in_seconds}" -lt "${MAX_BACKUP_AGE_SECONDS}" ]; then echo "Backup completed within the last ${MAX_BACKUP_AGE_SECONDS} seconds. Healthcheck passed." exit 0 fi +elif [ -f /health/container_start_time.log ]; then + current_time=$(date +%s) + start_time=$(date --file /health/container_start_time.log +%s) + age_in_seconds=$((current_time - start_time)) + + if [ "${age_in_seconds}" -lt "${MAX_BACKUP_AGE_SECONDS}" ]; then + echo "No backup completed yet, but container started less than ${MAX_BACKUP_AGE_SECONDS} seconds ago. Healthcheck passed." + exit 0 + fi fi echo "Backup not completed within the last ${MAX_BACKUP_AGE_SECONDS} seconds. Healthcheck failed." diff --git a/src/schedule.sh b/src/schedule.sh index 4956b0a..1ca95b1 100755 --- a/src/schedule.sh +++ b/src/schedule.sh @@ -11,6 +11,7 @@ get_log_file_name() { } echo "Starting schedule script at $(date)" | log_message +date > /health/container_start_time.log while true; do exec /src/backup-wrapper.sh 2>&1 | log_message