Skip to content

Commit 5a32c13

Browse files
committed
20211002 MariaDB health check - old-menu branch - PR 2 of 3
Follows on from suggestion in [Issue 415](#415) to add health-check to more containers. See also [PR 406](dbb6217). Changes: * Adds `iotstack_healthcheck.sh` script to template. * Adds commands to Dockerfile to copy that script into the local image and activate health-checking on launch. * Reduces old-menu MariaDB documentation to a stub pointing to new-menu documentation (this is already the situation for old-menu NextCloud documentation).
1 parent 46bbde9 commit 5a32c13

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

.templates/mariadb/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
RESPONSE=$(mysqladmin -p${MYSQL_ROOT_PASSWORD} ping -h localhost)
12+
13+
# did the mysqladmin command succeed?
14+
if [ $? -eq 0 ] ; then
15+
16+
# yes! is the response as expected?
17+
if [ "$RESPONSE" = "$EXPECTED" ] ; then
18+
19+
# yes! this could still be a false positive so probe the port
20+
if nc -w 1 localhost $HEALTHCHECK_PORT >/dev/null 2>&1; then
21+
22+
# port responding - that defines healthy
23+
exit 0
24+
25+
fi
26+
27+
fi
28+
29+
fi
30+
31+
# otherwise the check fails
32+
exit 1

docs/Containers/MariaDB.md

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
## Source
2-
* [Docker hub](https://hub.docker.com/r/linuxserver/mariadb/)
3-
* [Webpage](https://mariadb.org/)
1+
# MariaDB
42

5-
## About
6-
7-
MariaDB is a fork of MySQL. This is an unofficial image provided by linuxserver.io because there is no official image for arm
8-
9-
## Conneting to the DB
10-
11-
The port is 3306. It exists inside the docker network so you can connect via `mariadb:3306` for internal connections. For external connections use `<your Pis IP>:3306`
12-
13-
![image](https://user-images.githubusercontent.com/46672225/69734358-7f030800-1137-11ea-9874-7d2c86b3d239.png)
14-
15-
## Setup
16-
17-
Before starting the stack edit the `./services/mariadb/mariadb.env` file and set your access details. This is optional however you will only have one shot at the preconfig. If you start the container without setting the passwords then you will have to either delete its volume directory or enter the terminal and change manually
18-
19-
The env file has three commented fields for credentials, either **all three** must be commented or un-commented. You can't have only one or two, its all or nothing.
20-
21-
## Terminal
22-
23-
A terminal is provided to access mariadb by the cli. execute `./services/mariadb/terminal.sh`. You will need to run `mysql -uroot -p` to enter mariadbs interface
3+
Please refer to the [documentation on the master branch](https://sensorsiot.github.io/IOTstack/Containers/MariaDB/).

0 commit comments

Comments
 (0)