@@ -39,6 +39,12 @@ file_env() {
39
39
unset " $fileVar "
40
40
}
41
41
42
+ # check to see if this file is being run or sourced from another script
43
+ _is_sourced () {
44
+ # https://unix.stackexchange.com/a/215279
45
+ [ " ${FUNCNAME[${#FUNCNAME[@]} - 1]}" == ' source' ]
46
+ }
47
+
42
48
# usage: docker_process_init_files [file [file [...]]]
43
49
# ie: docker_process_init_files /always-initdb.d/*
44
50
# process initializer files, based on file extensions
@@ -149,8 +155,10 @@ docker_init_database_dir() {
149
155
}
150
156
151
157
# Loads various settings that are used elsewhere in the script
158
+ # This should be called after mysql_check_config, but before any other functions
152
159
docker_setup_env () {
153
160
# Get config
161
+ declare -g DATADIR SOCKET
154
162
DATADIR=" $( mysql_get_config ' datadir' " $@ " ) "
155
163
SOCKET=" $( mysql_get_config ' socket' " $@ " ) "
156
164
@@ -282,9 +290,9 @@ _main() {
282
290
if [ " $1 " = ' mysqld' ] && ! _mysql_want_help " $@ " ; then
283
291
mysql_note " Entrypoint script for MySQL Server ${MYSQL_VERSION} started."
284
292
293
+ mysql_check_config " $@ "
285
294
# Load various environment variables
286
295
docker_setup_env " $@ "
287
- mysql_check_config " $@ "
288
296
docker_create_db_directories
289
297
290
298
# If container is started as root user, restart as dedicated mysql user
@@ -319,9 +327,7 @@ _main() {
319
327
exec " $@ "
320
328
}
321
329
322
- # This checks if the script has been sourced from elsewhere.
323
- # If so we don't perform any further actions
324
- # https://unix.stackexchange.com/a/215279
325
- if [ " ${FUNCNAME[${#FUNCNAME[@]} - 1]}" != ' source' ]; then
330
+ # If we are sourced from elsewhere, don't perform any further actions
331
+ if ! _is_sourced; then
326
332
_main " $@ "
327
333
fi
0 commit comments