Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit d9ff540

Browse files
authored
fix: MySQL health checks need to happen over TCP (#1207)
By using the correct health check (TCP, rather than UNIX socket) we can get rid of the 10 second sleep. See docker-library/mysql#930 for discussion of health checks. This commit also simplifies the wait-for-mysql code in the provisioning script.
1 parent e0f04a7 commit d9ff540

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

Diff for: Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ dev.dbcopyall8: ## Clean mysql80 container and copy data from old mysql 5.7 cont
470470
docker volume rm devstack_mysql80_data
471471
$(MAKE) dev.up.mysql57+mysql80
472472
$(MAKE) dev.wait-for.mysql57+mysql80
473-
sleep 10
474473
docker compose exec -T mysql80 mysql -uroot mysql < provision-mysql80.sql
475474
$(MAKE) $(_db_copy8_targets)
476475
$(MAKE) stop

Diff for: check.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,18 @@ run_check() {
5656
mysql_run_check() {
5757
container_name="$1"
5858
mysql_probe="SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')"
59+
# The use of `--protocol tcp` forces MySQL to connect over TCP rather than
60+
# via a UNIX socket. This is needed because when MySQL starts for the first
61+
# time in a new container, it starts a "temporary server" that runs for a
62+
# few seconds and then shuts down before the "real" server starts up. The
63+
# temporary server does not listen on the TCP port, but if the mysql
64+
# command is not told which server to use, it will first try the UNIX
65+
# socket and only after that will it try the default TCP port.
66+
#
67+
# By specifying that mysql should use TCP, we won't get an early false
68+
# positive "ready" response while the temporary server is running.
5969
run_check "${container_name}_query" "$container_name" \
60-
"docker compose exec -T $(printf %q "$container_name") mysql -uroot -se $(printf %q "$mysql_probe")"
70+
"docker compose exec -T $(printf %q "$container_name") mysql --protocol tcp -uroot -se $(printf %q "$mysql_probe")"
6171
}
6272

6373
if should_check mysql57; then

Diff for: provision.sh

+4-19
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,10 @@ if needs_mongo "$to_provision_ordered"; then
128128
docker compose up -d mongo
129129
fi
130130

131-
# Ensure the MySQL5 server is online and usable
132-
echo "${GREEN}Waiting for MySQL 5.7.${NC}"
133-
make dev.wait-for.mysql57
134-
135-
# Ensure the MySQL8 server is online and usable
136-
echo "${GREEN}Waiting for MySQL 8.0.${NC}"
137-
make dev.wait-for.mysql80
138-
139-
# In the event of a fresh MySQL container, wait a few seconds for the server to restart
140-
# See https://github.com/docker-library/mysql/issues/245 for why this is necessary.
141-
sleep 10
142-
143-
echo "${GREEN}Waiting for MySQL 5.7 to restart.${NC}"
144-
make dev.wait-for.mysql57
145-
echo -e "${GREEN}MySQL5 ready.${NC}"
146-
147-
echo "${GREEN}Waiting for MySQL 8.0 to restart.${NC}"
148-
make dev.wait-for.mysql80
149-
echo -e "${GREEN}MySQL8 ready.${NC}"
131+
# Ensure the MySQL server is online and usable
132+
echo -e "${GREEN}Waiting for MySQL.${NC}"
133+
make dev.wait-for.mysql57+mysql80
134+
echo -e "${GREEN}MySQL is ready.${NC}"
150135

151136
# Ensure that the MySQL databases and users are created for all IDAs.
152137
# (A no-op for databases and users that already exist).

0 commit comments

Comments
 (0)