Skip to content

Commit

Permalink
Add debugging info into passwd-change script
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorak committed Dec 10, 2017
1 parent b63563f commit d4765c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions root-common/usr/share/container-scripts/mysql/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ function log_and_run {
"$@"
}

function log_debug {
CONTAINER_DEBUG=${CONTAINER_DEBUG:-}
if [[ "${CONTAINER_DEBUG,,}" != "true" ]]; then
return
fi
log_info $@
}

function log_volume_info {
CONTAINER_DEBUG=${CONTAINER_DEBUG:-}
if [[ "${CONTAINER_DEBUG,,}" != "true" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ password_change() {
# Set the password for MySQL user and root everytime this container is started.
# This allows to change the password by editing the deployment configuration.
if [[ -v MYSQL_USER && -v MYSQL_PASSWORD ]]; then
log_debug "About to change password for user '${MYSQL_USER}'."
mysql $mysql_flags <<EOSQL
SET PASSWORD FOR '${MYSQL_USER}'@'%' = PASSWORD('${MYSQL_PASSWORD}');
EOSQL
log_debug 'Password for user '${MYSQL_USER}' changed.'
fi

# The MYSQL_ROOT_PASSWORD is optional, therefore we need to either enable remote
Expand All @@ -15,13 +17,14 @@ EOSQL
# GRANT will create a user if it doesn't exist on 5.6 and lower, but we
# need to explicitly call CREATE USER in 5.7 and higher
# then set its password
log_debug "About to change password for user 'root'."
if [ "$MYSQL_VERSION" \> "5.6" ] ; then
mysql $mysql_flags <<EOSQL
CREATE USER IF NOT EXISTS 'root'@'%';
EOSQL
fi
mysql $mysql_flags <<EOSQL
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' WITH GRANT OPTION;
EOSQL
else
if [ "$MYSQL_VERSION" \> "5.6" ] ; then
Expand All @@ -38,11 +41,15 @@ mysql $mysql_flags <<EOSQL
FLUSH PRIVILEGES;
EOSQL
fi
log_debug "Password for 'root' user changed."
fi
}

if ! [ -v MYSQL_RUNNING_AS_SLAVE ] ; then
password_change
if ! password_change ; then
log_info "Changing password failed."
return 1
fi
fi

unset -f password_change

0 comments on commit d4765c3

Please sign in to comment.