Skip to content

Commit 9cf173b

Browse files
committed
Extract host and port from DB_HOST
1 parent 99ac907 commit 9cf173b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

root/etc/cont-init.d/50-config

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,21 @@ if ! grep -qx '^post_max_size.*$' /config/php/php-local.ini; then
9696
echo 'post_max_size = 100M' >> /config/php/php-local.ini
9797
fi
9898

99+
# extract actual host and port from DB_HOST endpoint format, not support IPv6
100+
# DB_HOST enpoint 'domainIp:port' or 'domainIp'
101+
# DB_HOST_ONLY drop ':port' portion
102+
# DB_PORT_ONLY drop host_only portion, remains '' or ':port'
103+
# DB_PORT_ONLY drop ':' if any, remain '' or 'port'
104+
# ${DB_PORT_ONLY:-3306} use default 3306 if missing
105+
DB_HOST_ONLY=${DB_HOST%:*}
106+
DB_PORT_ONLY=${DB_HOST#$DB_HOST_ONLY}
107+
DB_PORT_ONLY=${DB_PORT_ONLY#:}
108+
99109
# check for the mysql endpoint for 30 seconds
100110
END=$((SECONDS+30))
101-
while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST+x}" ]; do
102-
if /usr/bin/nc -z ${DB_HOST} 3306; then
103-
if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST} 3306)" ]; then
111+
while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST_ONLY+x}" ]; do
112+
if /usr/bin/nc -z ${DB_HOST_ONLY} ${DB_PORT_ONLY:-3306}; then
113+
if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST_ONLY} ${DB_PORT_ONLY:-3306})" ]; then
104114
if [ ! -z "${RUN}" ]; then
105115
break
106116
fi

0 commit comments

Comments
 (0)