mirror of
https://github.com/ViViDboarder/docker-restic-cron.git
synced 2024-12-23 03:57:43 +00:00
Add healthcheck to Docker image
This commit is contained in:
parent
b2fd9d4259
commit
fa9c0f9798
@ -49,9 +49,13 @@ RUN mkdir -p /scripts/backup/after
|
||||
RUN mkdir -p /scripts/restore/before
|
||||
RUN mkdir -p /scripts/restore/after
|
||||
|
||||
ADD backup.sh /
|
||||
ADD restore.sh /
|
||||
ADD start.sh /
|
||||
ADD verify.sh /
|
||||
COPY backup.sh /
|
||||
COPY restore.sh /
|
||||
COPY start.sh /
|
||||
COPY verify.sh /
|
||||
COPY healthcheck.sh /
|
||||
COPY cron-exec.sh /
|
||||
|
||||
HEALTHCHECK CMD /healthcheck.sh
|
||||
|
||||
CMD [ "/start.sh" ]
|
||||
|
@ -49,9 +49,13 @@ RUN mkdir -p /scripts/backup/after
|
||||
RUN mkdir -p /scripts/restore/before
|
||||
RUN mkdir -p /scripts/restore/after
|
||||
|
||||
ADD backup.sh /
|
||||
ADD restore.sh /
|
||||
ADD start.sh /
|
||||
ADD verify.sh /
|
||||
COPY backup.sh /
|
||||
COPY restore.sh /
|
||||
COPY start.sh /
|
||||
COPY verify.sh /
|
||||
COPY healthcheck.sh /
|
||||
COPY cron-exec.sh /
|
||||
|
||||
HEALTHCHECK CMD /healthcheck.sh
|
||||
|
||||
CMD [ "/start.sh" ]
|
||||
|
10
cron-exec.sh
Executable file
10
cron-exec.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#! /bin/bash
|
||||
|
||||
ENV=/env
|
||||
LOG=/cron.log
|
||||
HEALTH_FILE=/unhealthy
|
||||
|
||||
test -f $ENV || echo NO_ENV=true > $ENV
|
||||
|
||||
# Execute command and write output to log
|
||||
env `cat $ENV | xargs` $@ 2>> $LOG && rm -f $HEALTH_FILE || { touch $HEALTH_FILE; exit 1; }
|
5
healthcheck.sh
Executable file
5
healthcheck.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#! /bin/bash
|
||||
|
||||
HEALTH_FILE=/unhealthy
|
||||
|
||||
test -f $HEALTH_FILE || exit 0 && exit 1
|
14
start.sh
14
start.sh
@ -18,34 +18,34 @@ fi
|
||||
|
||||
# If set to restore on start, restore if the data volume is empty
|
||||
if [ "$RESTORE_ON_EMPTY_START" == "true" -a -z "$(ls -A $PATH_TO_BACKUP)" ]; then
|
||||
/restore.sh
|
||||
/cron-exec.sh /restore.sh
|
||||
fi
|
||||
|
||||
# Unless explicitly skipping, take a backup on startup
|
||||
if [ "$SKIP_ON_START" != "true" ]; then
|
||||
/backup.sh
|
||||
/cron-exec.sh /backup.sh
|
||||
fi
|
||||
|
||||
if [ -n "$CRON_SCHEDULE" ]; then
|
||||
# Export the environment to a file so it can be loaded from cron
|
||||
env | sed 's/^\(.*\)=\(.*\)$/export \1="\2"/g' > /env.sh
|
||||
env > /env
|
||||
# Remove some vars we don't want to keep
|
||||
sed -i '/\(HOSTNAME\|affinity\|SHLVL\|PWD\)/d' /env.sh
|
||||
sed -i '/\(HOSTNAME\|affinity\|SHLVL\|PWD\)/d' /env
|
||||
|
||||
# Use bash for cron
|
||||
echo "SHELL=/bin/bash" > /crontab.conf
|
||||
|
||||
# Schedule the backups
|
||||
echo "$CRON_SCHEDULE source /env.sh && /backup.sh 2>> /cron.log" >> /crontab.conf
|
||||
echo "$CRON_SCHEDULE /cron-exec.sh /backup.sh" >> /crontab.conf
|
||||
echo "Backups scheduled as $CRON_SCHEDULE"
|
||||
|
||||
if [ -n "$FULL_CRON_SCHEDULE" ]; then
|
||||
echo "$FULL_CRON_SCHEDULE source /env.sh && /backup.sh full 2>> /cron.log" >> /crontab.conf
|
||||
echo "$FULL_CRON_SCHEDULE /cron-exec.sh /backup.sh full" >> /crontab.conf
|
||||
echo "Full backup scheduled as $VERIFY_CRON_SCHEDULE"
|
||||
fi
|
||||
|
||||
if [ -n "$VERIFY_CRON_SCHEDULE" ]; then
|
||||
echo "$VERIFY_CRON_SCHEDULE source /env.sh && /verify.sh 2>> /cron.log" >> /crontab.conf
|
||||
echo "$VERIFY_CRON_SCHEDULE /cron-exec.sh /verify.sh" >> /crontab.conf
|
||||
echo "Verify scheduled as $VERIFY_CRON_SCHEDULE"
|
||||
fi
|
||||
|
||||
|
@ -22,10 +22,10 @@ else
|
||||
mkdir -p /data && echo Test > /data/test.txt
|
||||
|
||||
echo "Making backup..."
|
||||
/backup.sh
|
||||
/cron-exec.sh /backup.sh
|
||||
|
||||
echo "Verify backup..."
|
||||
/verify.sh
|
||||
/cron-exec.sh /verify.sh
|
||||
|
||||
echo "Delete test data..."
|
||||
rm -fr /data/*
|
||||
@ -34,7 +34,8 @@ else
|
||||
test -f /data/test.txt && exit 1 || echo "Gone"
|
||||
|
||||
echo "Restore backup..."
|
||||
/restore.sh
|
||||
/cron-exec.sh /restore.sh
|
||||
/healthcheck.sh
|
||||
|
||||
echo "Verify restore..."
|
||||
test -f /data/test.txt
|
||||
@ -51,6 +52,7 @@ else
|
||||
|
||||
echo "Simulate a restart with RESTORE_ON_EMPTY_START..."
|
||||
RESTORE_ON_EMPTY_START=true /start.sh
|
||||
/healthcheck.sh
|
||||
|
||||
echo "Verify restore happened..."
|
||||
test -f /data/test.txt
|
||||
@ -58,5 +60,8 @@ else
|
||||
|
||||
echo "Verify restore with incorrect passphrase fails..."
|
||||
echo "Fail to restore backup..."
|
||||
PASSPHRASE=Incorrect.Mule.Solar.Paperclip /restore.sh && exit 1 || echo "OK"
|
||||
PASSPHRASE=Incorrect.Mule.Solar.Paperclip /cron-exec.sh /restore.sh && exit 1 || echo "OK"
|
||||
|
||||
echo "Verify failed healthcheck"
|
||||
/healthcheck.sh && exit 1 || echo "OK"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user