Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bz1505037: Add debugging info into passwd-change script #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:-}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this documented somewhere?

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