Skip to content

Commit c9600d2

Browse files
ltangvaldyosifkit
authored andcommitted
Rename log functions from docker to mysql
1 parent 34ae313 commit c9600d2

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

.template.Debian/docker-entrypoint.sh

+33-33
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ set -eo pipefail
33
shopt -s nullglob
44

55
# logging functions
6-
docker_log() {
6+
mysql_log() {
77
local type=$1;shift
88
printf "$(date --rfc-3339=seconds) [${type}] [Entrypoint]: $@\n"
99
}
10-
docker_note() {
11-
docker_log Note "$@"
10+
mysql_note() {
11+
mysql_log Note "$@"
1212
}
13-
docker_warn() {
14-
docker_log Warn "$@" >&2
13+
mysql_warn() {
14+
mysql_log Warn "$@" >&2
1515
}
16-
docker_error() {
17-
docker_log ERROR "$@" >&2
16+
mysql_error() {
17+
mysql_log ERROR "$@" >&2
1818
exit 1
1919
}
2020

@@ -43,7 +43,7 @@ file_env() {
4343
local fileVar="${var}_FILE"
4444
local def="${2:-}"
4545
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
46-
docker_error "Both $var and $fileVar are set (but are exclusive)"
46+
mysql_error "Both $var and $fileVar are set (but are exclusive)"
4747
fi
4848
local val="$def"
4949
if [ "${!var:-}" ]; then
@@ -65,18 +65,18 @@ docker_process_init_files() {
6565
local mysql=( "$@" )
6666

6767
case "$f" in
68-
*.sh) docker_note "$0: running $f"; . "$f" ;;
69-
*.sql) docker_note "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
70-
*.sql.gz) docker_note "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
71-
*) docker_warn "$0: ignoring $f" ;;
68+
*.sh) mysql_note "$0: running $f"; . "$f" ;;
69+
*.sql) mysql_note "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
70+
*.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
71+
*) mysql_warn "$0: ignoring $f" ;;
7272
esac
7373
echo
7474
}
7575

7676
mysql_check_config() {
7777
toRun=( "$@" --verbose --help )
7878
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
79-
docker_error "mysqld failed while attempting to check config\n\tcommand was: ${toRun[*]}\n\t$errors"
79+
mysql_error "mysqld failed while attempting to check config\n\tcommand was: ${toRun[*]}\n\t$errors"
8080
fi
8181
}
8282

@@ -95,7 +95,7 @@ docker_start_server() {
9595
result=0
9696
%%SERVERSTARTUP%%
9797
if [ "$result" != "0" ];then
98-
docker_error "Unable to start server. Status code $result."
98+
mysql_error "Unable to start server. Status code $result."
9999
fi
100100
}
101101

@@ -110,7 +110,7 @@ docker_wait_for_server() {
110110
sleep 1
111111
done
112112
if [ "$i" = 0 ]; then
113-
docker_error "Unable to start server."
113+
mysql_error "Unable to start server."
114114
fi
115115
}
116116

@@ -120,30 +120,30 @@ docker_stop_server() {
120120
result=0
121121
mysqladmin --defaults-extra-file="${PASSFILE}" shutdown -uroot --socket="${SOCKET}" || result=$?
122122
if [ "$result" != "0" ]; then
123-
docker_error "Unable to shut down server. Status code $result."
123+
mysql_error "Unable to shut down server. Status code $result."
124124
fi
125125
}
126126

127127
# Verify that the minimally required password settings are set for new databases.
128128
docker_verify_minimum_env() {
129129
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
130-
docker_error "Database is uninitialized and password option is not specified \n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD"
130+
mysql_error "Database is uninitialized and password option is not specified \n\tYou need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD"
131131
fi
132132
}
133133

134134
# Creates and initializes the database directory
135135
docker_init_database_dir() {
136136
mkdir -p "$DATADIR"
137137

138-
docker_note "Initializing database files"
138+
mysql_note "Initializing database files"
139139
%%DATABASEINIT%%
140-
docker_note "Database files initialized"
140+
mysql_note "Database files initialized"
141141

142142
if command -v mysql_ssl_rsa_setup > /dev/null && [ ! -e "$DATADIR/server-key.pem" ]; then
143143
# https://github.com/mysql/mysql-server/blob/23032807537d8dd8ee4ec1c4d40f0633cd4e12f9/packaging/deb-in/extra/mysql-systemd-start#L81-L84
144-
docker_note "Initializing certificates"
144+
mysql_note "Initializing certificates"
145145
mysql_ssl_rsa_setup --datadir="$DATADIR"
146-
docker_note "Certificates initialized"
146+
mysql_note "Certificates initialized"
147147
fi
148148
}
149149

@@ -210,13 +210,13 @@ docker_init_root_user() {
210210
# Creates a custom database and user if specified
211211
docker_init_database_user() {
212212
if [ "$MYSQL_DATABASE" ]; then
213-
docker_note "Creating database ${MYSQL_DATABASE}"
213+
mysql_note "Creating database ${MYSQL_DATABASE}"
214214
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
215215
mysql+=( "$MYSQL_DATABASE" )
216216
fi
217217

218218
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
219-
docker_note "Creating user ${MYSQL_USER}"
219+
mysql_note "Creating user ${MYSQL_USER}"
220220
echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" | "${mysql[@]}"
221221

222222
if [ "$MYSQL_DATABASE" ]; then
@@ -231,7 +231,7 @@ docker_init_database_user() {
231231
# else can be done (only supported for 5.6+)
232232
docker_expire_root_user() {
233233
if [ "${MYSQL_MAJOR}" = "5.5" ]; then
234-
_warn "MySQL 5.5 does not support PASSWORD EXPIRE (required for MYSQL_ONETIME_PASSWORD)"
234+
mysql_warn "MySQL 5.5 does not support PASSWORD EXPIRE (required for MYSQL_ONETIME_PASSWORD)"
235235
else
236236
"${mysql[@]}" <<-EOSQL
237237
ALTER USER 'root'@'%' PASSWORD EXPIRE;
@@ -242,7 +242,7 @@ docker_expire_root_user() {
242242
# Generate a random root password
243243
docker_generate_root_password() {
244244
export MYSQL_ROOT_PASSWORD="$(pwgen -1 32)"
245-
docker_note "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
245+
mysql_note "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
246246
}
247247

248248
# Load timezone info into database
@@ -252,7 +252,7 @@ docker_load_tzinfo() {
252252
}
253253

254254
docker_main() {
255-
docker_note "Entrypoint script for MySQL Server ${MYSQL_VERSION} started."
255+
mysql_note "Entrypoint script for MySQL Server ${MYSQL_VERSION} started."
256256

257257
if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
258258
# Load various environment variables
@@ -263,7 +263,7 @@ docker_main() {
263263
mysql_check_config "$@"
264264
mkdir -p "$DATADIR"
265265
chown -R mysql:mysql "$DATADIR"
266-
docker_note "Switching to dedicated user 'mysql'"
266+
mysql_note "Switching to dedicated user 'mysql'"
267267
exec gosu mysql "$BASH_SOURCE" "$@"
268268
fi
269269

@@ -276,14 +276,14 @@ docker_main() {
276276
docker_init_database_dir "$@"
277277
docker_init_client_command
278278

279-
docker_note "Starting temporary server"
279+
mysql_note "Starting temporary server"
280280
docker_start_server "$@"
281281
# For 5.7+ the server is ready for use as soon as startup command unblocks
282282
if [ "${MYSQL_MAJOR}" = "5.5" ] || [ "${MYSQL_MAJOR}" = "5.6" ]; then
283-
docker_note "Waiting for server startup"
283+
mysql_note "Waiting for server startup"
284284
docker_wait_for_server "${mysql[@]}"
285285
fi
286-
docker_note "Temporary server started."
286+
mysql_note "Temporary server started."
287287

288288

289289
if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then
@@ -308,15 +308,15 @@ docker_main() {
308308
if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then
309309
docker_expire_root_user
310310
fi
311-
docker_note "Stopping temporary server"
311+
mysql_note "Stopping temporary server"
312312
docker_stop_server
313-
docker_note "Temporary server stopped"
313+
mysql_note "Temporary server stopped"
314314

315315
# Remove the password file now that initialization is complete
316316
rm -f "${PASSFILE}"
317317
unset PASSFILE
318318
echo
319-
docker_note "MySQL init process done. Ready for start up."
319+
mysql_note "MySQL init process done. Ready for start up."
320320
echo
321321
fi
322322
fi

0 commit comments

Comments
 (0)