Skip to content

Commit 71750e1

Browse files
committed
Support DB_PORT
1 parent 9cf173b commit 71750e1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ mkdir -p \
1313
# check for .env and copy default if needed
1414
if [[ ! -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
1622
fi
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
7182
fi
7283

7384
# set appurl
@@ -101,16 +112,16 @@ fi
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
105116
DB_HOST_ONLY=${DB_HOST%:*}
106117
DB_PORT_ONLY=${DB_HOST#$DB_HOST_ONLY}
107118
DB_PORT_ONLY=${DB_PORT_ONLY#:}
108119

109120
# check for the mysql endpoint for 30 seconds
110121
END=$((SECONDS+30))
111122
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
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

Comments
 (0)