diff --git a/Dockerfile b/Dockerfile index 051b26d..2a95ed6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,4 +41,7 @@ RUN mkdir /backup && \ VOLUME ["/backup"] -CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh +HEALTHCHECK --interval=2s --retries=1800 \ + CMD stat /HEALTHY.status || exit 1 + +ENTRYPOINT dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh \ No newline at end of file diff --git a/README.md b/README.md index 1786703..6627b0d 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ docker container run -d \ fradelg/mysql-cron-backup ``` +### Healthcheck + + +Healthcheck is provided as a basic init control. +Container is **Healthy** after the database init phase, that is after `INIT_BACKUP` or `INIT_RESTORE_LATEST` happends without check if there is an error, **Starting** otherwise. Not other checks are actually provided. + ## Variables diff --git a/run.sh b/run.sh index 5990e0a..17a420c 100755 --- a/run.sh +++ b/run.sh @@ -28,6 +28,8 @@ if [ -n "${EXIT_BACKUP}" ]; then trap final_backup SIGHUP SIGINT SIGTERM fi +touch /HEALTHY.status + echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf crontab /tmp/crontab.conf echo "=> Running cron task manager in foreground"