@@ -13,6 +13,12 @@ mkdir -p \
13
13
# check for .env and copy default if needed
14
14
if [[ ! -f "/config/www/.env" ]] || [[ ! -s "/config/www/.env" ]]; then
15
15
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
16
22
fi
17
23
18
24
# create symlinks
@@ -68,6 +74,11 @@ if [ "${DB_USER}" ];
68
74
sed -i "s/DB_DATABASE=database_database/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env
69
75
sed -i "s/DB_USERNAME=database_username/DB_USERNAME=${DB_USER}/g" /config/www/.env
70
76
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
71
82
fi
72
83
73
84
# set appurl
101
112
# DB_HOST_ONLY drop ':port' portion
102
113
# DB_PORT_ONLY drop host_only portion, remains '' or ':port'
103
114
# 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
105
116
DB_HOST_ONLY=${DB_HOST%:*}
106
117
DB_PORT_ONLY=${DB_HOST#$DB_HOST_ONLY}
107
118
DB_PORT_ONLY=${DB_PORT_ONLY#:}
108
119
109
120
# check for the mysql endpoint for 30 seconds
110
121
END=$((SECONDS+30))
111
122
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
114
125
if [ ! -z "${RUN}" ]; then
115
126
break
116
127
fi
0 commit comments