Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use mariadb client for healthchecks #221

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*
!sh/run.sh
!sh/health.sh
!sh/clean.sh
!sh/resolveip.sh
!sh/my_print_defaults.sh
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ RUN \
# my_print_defaults should cover 95% of cases since it doesn't properly do recursion
COPY sh/resolveip.sh /usr/bin/resolveip
COPY sh/my_print_defaults.sh /usr/bin/my_print_defaults
COPY sh/run.sh /run.sh
COPY sh/run.sh sh/health.sh /
# Used in run.sh as a default config
COPY my.cnf /tmp/my.cnf

# This is not super helpful; mysqld might be running but not accepting connections.
# Since we have no clients, we can't really connect to it and check.
#
# Below is in my opinion better than no health check.
HEALTHCHECK --start-period=5s CMD pgrep mariadbd
HEALTHCHECK --start-period=5s CMD /health.sh

VOLUME ["/var/lib/mysql"]
ENTRYPOINT ["/run.sh"]
Expand Down
17 changes: 17 additions & 0 deletions sh/health.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# shellcheck shell=dash
set -eo pipefail

CHECK="mariadb"

# prefer root if available
if [ -n "${MYSQL_ROOT_PASSWORD}" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ENV is not reliable since it can be changed right after the first warm up

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my first point/todo and the first comment. MariaDB health check ignores auth and mysql ignores healthchecks altogether.

Copy link
Owner Author

@jbergstroem jbergstroem Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we want is a sane default, if people do changes they should probably override the healthcheck as well. I can see this being very common in any kind of setup where you orchestrate a docker compose setup with many actors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth providing ENVs for the check, and if they are all empty then it does nothing ?

Copy link
Owner Author

@jbergstroem jbergstroem Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they are all empty it would try to connect without credentials. This is what mariadb does.

CHECK="${CHECK} --user=root --password=${MYSQL_ROOT_PASSWORD}"
else
[ -n "${MYSQL_DATABASE}" ] && CHECK="${CHECK} --database=${MYSQL_DATABASE}"
[ -n "${MYSQL_USERNAME}" ] && CHECK="${CHECK} --user=${MYSQL_USERNAME}"
[ -n "${MYSQL_PASSWORD}" ] && CHECK="${CHECK} --password=${MYSQL_PASSWORD}"
fi
CHECK="${CHECK} -e 'select 1;'"

eval ${CHECK}
jbergstroem marked this conversation as resolved.
Show resolved Hide resolved