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

20211002 MariaDB health check - experimental branch - PR 3 of 3 #418

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,16 @@ RUN sed -i.bak \
-e "s/^read_buffer_size/# read_buffer_size/" \
/defaults/my.cnf

# copy the health-check script into place
ENV HEALTHCHECK_SCRIPT "iotstack_healthcheck.sh"
COPY ${HEALTHCHECK_SCRIPT} /usr/local/bin/${HEALTHCHECK_SCRIPT}

# define the health check
HEALTHCHECK \
--start-period=30s \
--interval=30s \
--timeout=10s \
--retries=3 \
CMD ${HEALTHCHECK_SCRIPT} || exit 1

# EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env sh

# set a default for the port
# (refer https://mariadb.com/kb/en/mariadb-environment-variables/ )
HEALTHCHECK_PORT="${MYSQL_TCP_PORT:-3306}"

# the expected response is?
EXPECTED="mysqld is alive"

# run the check
if [ -z "$MYSQL_ROOT_PASSWORD" ] ; then
RESPONSE=$(mysqladmin ping -h localhost)
else
# note - there is NO space between "-p" and the password. This is
# intentional. It is part of the mysql and mysqladmin API.
RESPONSE=$(mysqladmin -p${MYSQL_ROOT_PASSWORD} ping -h localhost)
fi

# did the mysqladmin command succeed?
if [ $? -eq 0 ] ; then

# yes! is the response as expected?
if [ "$RESPONSE" = "$EXPECTED" ] ; then

# yes! this could still be a false positive so probe the port
if nc -w 1 localhost $HEALTHCHECK_PORT >/dev/null 2>&1; then

# port responding - that defines healthy
exit 0

fi

fi

fi

# otherwise the check fails
exit 1