Skip to content

Extract host and port from DB_HOST also support DB_PORT to test connection instead of only use default port 3306 #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Dec 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions root/etc/cont-init.d/50-config
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,21 @@ if ! grep -qx '^post_max_size.*$' /config/php/php-local.ini; then
echo 'post_max_size = 100M' >> /config/php/php-local.ini
fi

# extract actual host and port from DB_HOST endpoint format, not support IPv6
# DB_HOST enpoint 'domainIp:port' or 'domainIp'
# DB_HOST_ONLY drop ':port' portion
# DB_PORT_ONLY drop host_only portion, remains '' or ':port'
# DB_PORT_ONLY drop ':' if any, remain '' or 'port'
# ${DB_PORT_ONLY:-3306} use default 3306 if missing
DB_HOST_ONLY=${DB_HOST%:*}
DB_PORT_ONLY=${DB_HOST#$DB_HOST_ONLY}
DB_PORT_ONLY=${DB_PORT_ONLY#:}

# check for the mysql endpoint for 30 seconds
END=$((SECONDS+30))
while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST+x}" ]; do
if /usr/bin/nc -z ${DB_HOST} 3306; then
if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST} 3306)" ]; then
while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST_ONLY+x}" ]; do
if /usr/bin/nc -z ${DB_HOST_ONLY} ${DB_PORT_ONLY:-3306}; then
if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST_ONLY} ${DB_PORT_ONLY:-3306})" ]; then
if [ ! -z "${RUN}" ]; then
break
fi
Expand Down