Skip to content

Commit 95e7856

Browse files
authored
Merge pull request SensorsIot#417 from Paraphraser/20211002-mariadb-healthcheck-old-menu
20211002 MariaDB health check - old-menu branch - PR 2 of 3
2 parents 30acee5 + 013eab7 commit 95e7856

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

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)