@@ -251,71 +251,76 @@ docker_load_tzinfo() {
251
251
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed ' s/Local time zone must be set--see zic manual page/FCTY/' | " ${mysql[@]} " mysql
252
252
}
253
253
254
- docker_init_env " $@ "
255
-
256
- # allow the container to be started with `--user`
257
- if [ " $1 " = ' mysqld' -a -z " $wantHelp " -a " $( id -u) " = ' 0' ]; then
258
- docker_check_config " $@ "
259
- mkdir -p " $DATADIR "
260
- chown -R mysql:mysql " $DATADIR "
261
- exec gosu mysql " $BASH_SOURCE " " $@ "
262
- fi
263
-
264
- docker_note " Entrypoint script for MySQL Server ${MYSQL_VERSION} started."
265
-
266
- if [ " $1 " = ' mysqld' -a -z " $wantHelp " ]; then
267
- # still need to check config, container may have started with --user
268
- docker_check_config " $@ "
269
-
270
- # If this is true then there's no database, and it needs to be initialized
271
- if [ ! -d " $DATADIR /mysql" ]; then
272
- docker_verify_env
273
- docker_init_database_dir " $@ "
274
- docker_init_client_command
275
-
276
- docker_note " Starting temporary server"
277
- docker_start_server " $@ "
278
- # For 5.7+ the server is ready for use as soon as startup command unblocks
279
- if [ " ${MYSQL_MAJOR} " = " 5.5" ] || [ " ${MYSQL_MAJOR} " = " 5.6" ]; then
280
- docker_note " Waiting for server startup"
281
- docker_wait_for_server " ${mysql[@]} "
254
+ docker_main () {
255
+ docker_note " Entrypoint script for MySQL Server ${MYSQL_VERSION} started."
256
+
257
+ if [ " $1 " = ' mysqld' -a -z " $wantHelp " ]; then
258
+ # Load various environment variables
259
+ docker_init_env " $@ "
260
+
261
+ # If container is started as root user, restart as dedicated mysql user
262
+ if [ " $( id -u) " = ' 0' ]; then
263
+ docker_check_config " $@ "
264
+ mkdir -p " $DATADIR "
265
+ chown -R mysql:mysql " $DATADIR "
266
+ docker_note " Switching to dedicated user 'mysql'"
267
+ exec gosu mysql " $BASH_SOURCE " " $@ "
282
268
fi
283
- docker_note " Temporary server started."
284
269
285
-
286
- if [ -z " $MYSQL_INITDB_SKIP_TZINFO " ]; then
287
- docker_load_tzinfo
270
+ # still need to check config, container may have started with --user
271
+ docker_check_config " $@ "
272
+
273
+ # If this is true then there's no database, and it needs to be initialized
274
+ if [ ! -d " $DATADIR /mysql" ]; then
275
+ docker_verify_env
276
+ docker_init_database_dir " $@ "
277
+ docker_init_client_command
278
+
279
+ docker_note " Starting temporary server"
280
+ docker_start_server " $@ "
281
+ # For 5.7+ the server is ready for use as soon as startup command unblocks
282
+ if [ " ${MYSQL_MAJOR} " = " 5.5" ] || [ " ${MYSQL_MAJOR} " = " 5.6" ]; then
283
+ docker_note " Waiting for server startup"
284
+ docker_wait_for_server " ${mysql[@]} "
285
+ fi
286
+ docker_note " Temporary server started."
287
+
288
+
289
+ if [ -z " $MYSQL_INITDB_SKIP_TZINFO " ]; then
290
+ docker_load_tzinfo
291
+ fi
292
+
293
+ if [ ! -z " $MYSQL_RANDOM_ROOT_PASSWORD " ]; then
294
+ docker_generate_root_password
295
+ fi
296
+
297
+ docker_init_root_user
298
+
299
+ docker_write_password_file
300
+
301
+ docker_init_database_user
302
+
303
+ echo
304
+ for f in /docker-entrypoint-initdb.d/* ; do
305
+ docker_process_init_file " $f " " ${mysql[@]} "
306
+ done
307
+
308
+ if [ ! -z " $MYSQL_ONETIME_PASSWORD " ]; then
309
+ docker_expire_root_user
310
+ fi
311
+ docker_note " Stopping temporary server"
312
+ docker_stop_server
313
+ docker_note " Temporary server stopped"
314
+
315
+ # Remove the password file now that initialization is complete
316
+ rm -f " ${PASSFILE} "
317
+ unset PASSFILE
318
+ echo
319
+ docker_note " MySQL init process done. Ready for start up."
320
+ echo
288
321
fi
289
-
290
- if [ ! -z " $MYSQL_RANDOM_ROOT_PASSWORD " ]; then
291
- docker_generate_root_password
292
- fi
293
-
294
- docker_init_root_user
295
-
296
- docker_write_password_file
297
-
298
- docker_init_database_user
299
-
300
- echo
301
- for f in /docker-entrypoint-initdb.d/* ; do
302
- docker_process_init_file " $f " " ${mysql[@]} "
303
- done
304
-
305
- if [ ! -z " $MYSQL_ONETIME_PASSWORD " ]; then
306
- docker_expire_root_user
307
- fi
308
- docker_note " Stopping temporary server"
309
- docker_stop_server
310
- docker_note " Temporary server stopped"
311
-
312
- # Remove the password file now that initialization is complete
313
- rm -f " ${PASSFILE} "
314
- unset PASSFILE
315
- echo
316
- docker_note " MySQL init process done. Ready for start up."
317
- echo
318
322
fi
319
- fi
323
+ exec " $@ "
324
+ }
320
325
321
- exec " $@ "
326
+ docker_main " $@ "
0 commit comments