@@ -13,6 +13,12 @@ mkdir -p \
1313# check for .env and copy default if needed
1414if [[ ! -f "/config/www/.env" ]] || [[ ! -s "/config/www/.env" ]]; then
1515 cp /app/www/.env.example /config/www/.env
16+
17+ if ! grep -Fxq "DB_PORT=3306" /config/www/.env; then
18+ # add line DB_PORT=3306 to /config/www/.env because current /app/www/.env.example dont have it
19+ sed -i "/DB_HOST=localhost/a DB_PORT=3306" /config/www/.env
20+ echo "**** Insert DB_PORT=3306 into /config/www/.env ****"
21+ fi
1622fi
1723
1824# create symlinks
@@ -68,6 +74,11 @@ if [ "${DB_USER}" ];
6874 sed -i "s/DB_DATABASE=database_database/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env
6975 sed -i "s/DB_USERNAME=database_username/DB_USERNAME=${DB_USER}/g" /config/www/.env
7076 sed -i "s/DB_PASSWORD=database_user_password/DB_PASSWORD=${ESCAPED_PASSWORD}/g" /config/www/.env
77+
78+ if [ "${DB_PORT}" ];
79+ then
80+ sed -i "s/DB_PORT=3306/DB_PORT=${DB_PORT}/g" /config/www/.env
81+ fi
7182fi
7283
7384# set appurl
101112# DB_HOST_ONLY drop ':port' portion
102113# DB_PORT_ONLY drop host_only portion, remains '' or ':port'
103114# DB_PORT_ONLY drop ':' if any, remain '' or 'port'
104- # ${DB_PORT_ONLY:-3306} use default 3306 if missing
115+ # ${DB_PORT_ONLY:-${DB_PORT:- 3306}} use DB_PORT if no port provided in DB_HOST, use default 3306 if not provide DB_PORT
105116DB_HOST_ONLY=${DB_HOST%:*}
106117DB_PORT_ONLY=${DB_HOST#$DB_HOST_ONLY}
107118DB_PORT_ONLY=${DB_PORT_ONLY#:}
108119
109120# check for the mysql endpoint for 30 seconds
110121END=$((SECONDS+30))
111122while [ ${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
123+ if /usr/bin/nc -z ${DB_HOST_ONLY} ${DB_PORT_ONLY:-${DB_PORT:- 3306} }; then
124+ if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST_ONLY} ${DB_PORT_ONLY:-${DB_PORT:- 3306} })" ]; then
114125 if [ ! -z "${RUN}" ]; then
115126 break
116127 fi
0 commit comments