Skip to content

Commit e8466f1

Browse files
committed
Add debugging info into passwd-change script
1 parent 6b5c285 commit e8466f1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

root-common/usr/share/container-scripts/mysql/helpers.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ function log_and_run {
77
"$@"
88
}
99

10+
function log_debug {
11+
CONTAINER_DEBUG=${CONTAINER_DEBUG:-}
12+
if [[ "${CONTAINER_DEBUG,,}" != "true" ]]; then
13+
return
14+
fi
15+
log_info $@
16+
}
17+
1018
function log_volume_info {
1119
CONTAINER_DEBUG=${CONTAINER_DEBUG:-}
1220
if [[ "${CONTAINER_DEBUG,,}" != "true" ]]; then

root-common/usr/share/container-scripts/mysql/init/50-passwd-change.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ password_change() {
44
# Set the password for MySQL user and root everytime this container is started.
55
# This allows to change the password by editing the deployment configuration.
66
if [[ -v MYSQL_USER && -v MYSQL_PASSWORD ]]; then
7+
log_debug "About to change password for user '${MYSQL_USER}'."
78
mysql $mysql_flags <<EOSQL
89
SET PASSWORD FOR '${MYSQL_USER}'@'%' = PASSWORD('${MYSQL_PASSWORD}');
910
EOSQL
11+
log_debug 'Password for user '${MYSQL_USER}' changed.'
1012
fi
1113

1214
# The MYSQL_ROOT_PASSWORD is optional, therefore we need to either enable remote
@@ -15,13 +17,14 @@ EOSQL
1517
# GRANT will create a user if it doesn't exist on 5.6 and lower, but we
1618
# need to explicitly call CREATE USER in 5.7 and higher
1719
# then set its password
20+
log_debug "About to change password for user 'root'."
1821
if [ "$MYSQL_VERSION" \> "5.6" ] ; then
1922
mysql $mysql_flags <<EOSQL
2023
CREATE USER IF NOT EXISTS 'root'@'%';
2124
EOSQL
2225
fi
2326
mysql $mysql_flags <<EOSQL
24-
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' WITH GRANT OPTION;
27+
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' WITH GRANT OPTION;
2528
EOSQL
2629
else
2730
if [ "$MYSQL_VERSION" \> "5.6" ] ; then
@@ -38,11 +41,15 @@ mysql $mysql_flags <<EOSQL
3841
FLUSH PRIVILEGES;
3942
EOSQL
4043
fi
44+
log_debug "Password for 'root' user changed."
4145
fi
4246
}
4347

4448
if ! [ -v MYSQL_RUNNING_AS_SLAVE ] ; then
45-
password_change
49+
if ! password_change ; then
50+
log_info "Changing password failed."
51+
return 1
52+
fi
4653
fi
4754

4855
unset -f password_change

0 commit comments

Comments
 (0)