Don't start unhealthy

This commit is contained in:
Andras Schmelczer 2026-03-22 17:40:57 +00:00
parent 8bc697a7f4
commit bfea98db61
2 changed files with 14 additions and 2 deletions

View file

@ -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."

View file

@ -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