Skip to content

Commit 03bdbad

Browse files
ltangvaldyosifkit
authored andcommitted
Add 5.5 and 5.6 to entrypoint templating
This requires adding some variables that are replaced when generating the entrypoint scripts
1 parent a9e8576 commit 03bdbad

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

.template.Debian/docker-entrypoint.sh

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,25 @@ _get_config() {
9393
_start_server() {
9494
local socket=$1; shift
9595
result=0
96-
"$@" --daemonize --skip-networking --socket="${socket}" || result=$?
96+
%%SERVERSTARTUP%%
9797
if [ ! "$result" = "0" ];then
9898
_error "Unable to start server. Status code $result."
9999
fi
100100
}
101101

102+
_wait_for_server() {
103+
local mysql=( "$@" )
104+
for i in {30..0}; do
105+
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
106+
break
107+
fi
108+
sleep 1
109+
done
110+
if [ "$i" = 0 ]; then
111+
_error "Unable to start server."
112+
fi
113+
}
114+
102115
_stop_server() {
103116
local passfile=$1
104117
local socket=$2
@@ -132,7 +145,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
132145
mkdir -p "$DATADIR"
133146

134147
_note "Initializing database"
135-
"$@" --initialize-insecure
148+
%%DATABASEINIT%%
136149
_note "Database initialized"
137150

138151
if command -v mysql_ssl_rsa_setup > /dev/null && [ ! -e "$DATADIR/server-key.pem" ]; then
@@ -143,11 +156,15 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
143156
fi
144157

145158
SOCKET="$(_get_config 'socket' "$@")"
159+
mysql=( mysql --no-defaults --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
146160
_note "Starting server"
147161
_start_server "${SOCKET}" "$@"
148-
_note "Server started with."
162+
if [ "${MYSQL_MAJOR}" = "5.5" ] || [ "${MYSQL_MAJOR}" = "5.6" ]; then
163+
_note "Waiting for server startup"
164+
_wait_for_server "${mysql[@]}"
165+
fi
166+
_note "Server started."
149167

150-
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
151168

152169
if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then
153170
# sed is for https://bugs.mysql.com/bug.php?id=20545
@@ -176,7 +193,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
176193
-- or products like mysql-fabric won't work
177194
SET @@SESSION.SQL_LOG_BIN=0;
178195
179-
ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
196+
%%PASSWORDSET%%
180197
GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION ;
181198
${rootCreate}
182199
DROP DATABASE IF EXISTS test ;
@@ -219,9 +236,13 @@ EOF
219236
done
220237

221238
if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then
222-
"${mysql[@]}" <<-EOSQL
223-
ALTER USER 'root'@'%' PASSWORD EXPIRE;
224-
EOSQL
239+
if [ "${MYSQL_MAJOR}" = "5.5" ]; then
240+
_warn "MySQL 5.5 does not support PASSWORD EXPIRE (required for MYSQL_ONETIME_PASSWORD)"
241+
else
242+
"${mysql[@]}" <<-EOSQL
243+
ALTER USER 'root'@'%' PASSWORD EXPIRE;
244+
EOSQL
245+
fi
225246
fi
226247
_note "Stopping server"
227248
_stop_server "${PASSFILE}" "${SOCKET}"

update.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,29 @@ declare -A debianVariants=(
1414
#[5.5]='jessie'
1515
)
1616

17-
# Copy entrypoint template
18-
templateVersions=( "5.7 8.0" )
17+
# Templaing
18+
templateVersions=( "5.5 5.6 5.7 8.0" )
19+
declare -A passwordset
20+
passwordset["5.5"]="SET PASSWORD FOR 'root'@'localhost'=PASSWORD('\${MYSQL_ROOT_PASSWORD}');"
21+
passwordset["5.6"]="SET PASSWORD FOR 'root'@'localhost'=PASSWORD('\${MYSQL_ROOT_PASSWORD}');"
22+
passwordset["5.7"]="ALTER USER 'root'@'localhost' IDENTIFIED BY '\${MYSQL_ROOT_PASSWORD}';"
23+
passwordset["8.0"]="ALTER USER 'root'@'localhost' IDENTIFIED BY '\${MYSQL_ROOT_PASSWORD}';"
24+
declare -A database_init
25+
database_init["5.5"]="mysql_install_db --datadir=\"\$DATADIR\" --rpm --basedir=\/usr\/local\/mysql \"\${@:2}\""
26+
database_init["5.6"]="mysql_install_db --user=mysql --datadir=\"\$DATADIR\" --rpm --keep-my-cnf"
27+
database_init["5.7"]="\"\$@\" --initialize-insecure"
28+
database_init["8.0"]="\"\$@\" --initialize-insecure"
29+
declare -A server_startup
30+
server_startup["5.5"]="\"\$@\" --skip-networking --basedir=\/usr\/local\/mysql --socket=\"\${socket}\" \&"
31+
server_startup["5.6"]="\"\$@\" --skip-networking --socket=\"\${socket}\" \&"
32+
server_startup["5.7"]="\"\$@\" --daemonize --skip-networking --socket=\"\${socket}\" || result=$?"
33+
server_startup["8.0"]="\"\$@\" --daemonize --skip-networking --socket=\"\${socket}\" || result=$?"
1934
for version in ${templateVersions}; do
2035
cp ".template.Debian/docker-entrypoint.sh" "${version}/"
36+
sed -e 's/%%PASSWORDSET%%/'"${passwordset["$version"]}"'/g' \
37+
-e 's/%%DATABASEINIT%%/'"${database_init["$version"]}"'/g' \
38+
-e 's/%%SERVERSTARTUP%%/'"${server_startup["$version"]}"'/g' \
39+
.template.Debian/docker-entrypoint.sh > "$version/docker-entrypoint.sh"
2140
done
2241

2342
for version in "${versions[@]}"; do

0 commit comments

Comments
 (0)