File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
.internal/templates/services/mariadb/buildFiles Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -10,4 +10,16 @@ RUN sed -i.bak \
1010 -e "s/^read_buffer_size/# read_buffer_size/" \
1111 /defaults/my.cnf
1212
13+ # copy the health-check script into place
14+ ENV HEALTHCHECK_SCRIPT "iotstack_healthcheck.sh"
15+ COPY ${HEALTHCHECK_SCRIPT} /usr/local/bin/${HEALTHCHECK_SCRIPT}
16+
17+ # define the health check
18+ HEALTHCHECK \
19+ --start-period=30s \
20+ --interval=30s \
21+ --timeout=10s \
22+ --retries=3 \
23+ CMD ${HEALTHCHECK_SCRIPT} || exit 1
24+
1325# EOF
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env sh
2+
3+ # set a default for the port
4+ # (refer https://mariadb.com/kb/en/mariadb-environment-variables/ )
5+ HEALTHCHECK_PORT=" ${MYSQL_TCP_PORT:- 3306} "
6+
7+ # the expected response is?
8+ EXPECTED=" mysqld is alive"
9+
10+ # run the check
11+ if [ -z " $MYSQL_ROOT_PASSWORD " ] ; then
12+ RESPONSE=$( mysqladmin ping -h localhost)
13+ else
14+ # note - there is NO space between "-p" and the password. This is
15+ # intentional. It is part of the mysql and mysqladmin API.
16+ RESPONSE=$( mysqladmin -p${MYSQL_ROOT_PASSWORD} ping -h localhost)
17+ fi
18+
19+ # did the mysqladmin command succeed?
20+ if [ $? -eq 0 ] ; then
21+
22+ # yes! is the response as expected?
23+ if [ " $RESPONSE " = " $EXPECTED " ] ; then
24+
25+ # yes! this could still be a false positive so probe the port
26+ if nc -w 1 localhost $HEALTHCHECK_PORT > /dev/null 2>&1 ; then
27+
28+ # port responding - that defines healthy
29+ exit 0
30+
31+ fi
32+
33+ fi
34+
35+ fi
36+
37+ # otherwise the check fails
38+ exit 1
You can’t perform that action at this time.
0 commit comments