Don't start unhealthy
This commit is contained in:
parent
8bc697a7f4
commit
bfea98db61
2 changed files with 14 additions and 2 deletions
|
|
@ -2,15 +2,26 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
MAX_BACKUP_AGE_SECONDS="${MAX_BACKUP_AGE_SECONDS:-86400}"
|
||||||
|
|
||||||
if [ -f /health/backup_completion_time.log ]; then
|
if [ -f /health/backup_completion_time.log ]; then
|
||||||
current_time=$(date +%s)
|
current_time=$(date +%s)
|
||||||
backup_time=$(date --file /health/backup_completion_time.log +%s)
|
backup_time=$(date --file /health/backup_completion_time.log +%s)
|
||||||
age_in_seconds=$((current_time - backup_time))
|
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."
|
echo "Backup completed within the last ${MAX_BACKUP_AGE_SECONDS} seconds. Healthcheck passed."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
fi
|
||||||
|
|
||||||
echo "Backup not completed within the last ${MAX_BACKUP_AGE_SECONDS} seconds. Healthcheck failed."
|
echo "Backup not completed within the last ${MAX_BACKUP_AGE_SECONDS} seconds. Healthcheck failed."
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ get_log_file_name() {
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Starting schedule script at $(date)" | log_message
|
echo "Starting schedule script at $(date)" | log_message
|
||||||
|
date > /health/container_start_time.log
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
exec /src/backup-wrapper.sh 2>&1 | log_message
|
exec /src/backup-wrapper.sh 2>&1 | log_message
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue