From 285d70bf23442ebb98dd878e357c2e76c048d1f2 Mon Sep 17 00:00:00 2001 From: Bitnami Bot Date: Fri, 11 Oct 2019 12:38:10 +0000 Subject: [PATCH] 5.7.27-ol-7-r93 release --- bitnami/mysql/5.7/ol-7/Dockerfile | 2 +- bitnami/mysql/5.7/ol-7/rootfs/entrypoint.sh | 3 +- bitnami/mysql/5.7/ol-7/rootfs/libmysql.sh | 217 ++++++++++---------- bitnami/mysql/5.7/ol-7/rootfs/run.sh | 3 +- bitnami/mysql/5.7/ol-7/rootfs/setup.sh | 3 +- bitnami/mysql/README.md | 2 +- 6 files changed, 118 insertions(+), 112 deletions(-) diff --git a/bitnami/mysql/5.7/ol-7/Dockerfile b/bitnami/mysql/5.7/ol-7/Dockerfile index 696c50200e13..89157b8b71cc 100644 --- a/bitnami/mysql/5.7/ol-7/Dockerfile +++ b/bitnami/mysql/5.7/ol-7/Dockerfile @@ -15,7 +15,7 @@ RUN mkdir /docker-entrypoint-initdb.d COPY rootfs / RUN /postunpack.sh ENV BITNAMI_APP_NAME="mysql" \ - BITNAMI_IMAGE_VERSION="5.7.27-ol-7-r92" \ + BITNAMI_IMAGE_VERSION="5.7.27-ol-7-r93" \ NAMI_PREFIX="/.nami" \ PATH="/opt/bitnami/mysql/bin:$PATH" diff --git a/bitnami/mysql/5.7/ol-7/rootfs/entrypoint.sh b/bitnami/mysql/5.7/ol-7/rootfs/entrypoint.sh index 8be54823dc66..b5dff5d708f3 100755 --- a/bitnami/mysql/5.7/ol-7/rootfs/entrypoint.sh +++ b/bitnami/mysql/5.7/ol-7/rootfs/entrypoint.sh @@ -1,10 +1,11 @@ #!/bin/bash +# shellcheck disable=SC1091 + set -o errexit set -o nounset set -o pipefail # set -o xtrace -# shellcheck disable=SC1091 # Load libraries . /libbitnami.sh diff --git a/bitnami/mysql/5.7/ol-7/rootfs/libmysql.sh b/bitnami/mysql/5.7/ol-7/rootfs/libmysql.sh index 3bdd64b44685..32337d60fbd4 100644 --- a/bitnami/mysql/5.7/ol-7/rootfs/libmysql.sh +++ b/bitnami/mysql/5.7/ol-7/rootfs/libmysql.sh @@ -102,7 +102,7 @@ EOF # None ######################### mysql_validate() { - info "Validating settings in MYSQL_*/MARIADB_* env vars.." + info "Validating settings in MYSQL_*/MARIADB_* env vars" local error_code=0 # Auxiliary functions @@ -169,7 +169,7 @@ mysql_validate() { # None ######################### mysql_create_config() { - debug "Creating main configuration file..." + debug "Creating main configuration file" cat > "$DB_CONFDIR/my.cnf" < "$DB_CONFDIR/bitnami/my_custom.cnf" fi local user_provided_conf=no @@ -296,61 +297,47 @@ mysql_initialize() { # Persisted configuration files from old versions ! is_dir_empty "$DB_VOLUMEDIR" && [[ -d "$DB_VOLUMEDIR/conf" ]] && migrate_old_configuration - debug "Ensuring expected directories/files exist..." + debug "Ensuring expected directories/files exist" for dir in "$DB_DATADIR" "$DB_TMPDIR" "$DB_LOGDIR"; do ensure_dir_exists "$dir" - am_i_root && chown "$DB_DAEMON_USER:$DB_DAEMON_GROUP" "$dir" + am_i_root && chown "$DB_DAEMON_USER":"$DB_DAEMON_GROUP" "$dir" done ! is_boolean_yes "$user_provided_conf" && mysql_create_config if [[ -e "$DB_DATADIR/mysql" ]]; then - info "Persisted data detected. Restoring..." - if [[ "$DB_FLAVOR" = "mysql" ]]; then - # if MYSQL/MARIADB_ROOT_PASSWORD is set, enable auth - [[ -n "$(get_master_env_var_value ROOT_PASSWORD)" ]] && export ROOT_AUTH_ENABLED="yes" - info "Running mysql_upgrade..." - mysql_start_bg - mysql_upgrade - fi + info "Using persisted data" + # mysql_upgrade requires the server to be running + [[ -n "$(get_master_env_var_value ROOT_PASSWORD)" ]] && export ROOT_AUTH_ENABLED="yes" + # https://dev.mysql.com/doc/refman/8.0/en/replication-upgrade.html + mysql_upgrade else - debug "Cleaning data directory to ensure successfully initialization..." + debug "Cleaning data directory to ensure successfully initialization" rm -rf "${DB_DATADIR:?}"/* + info "Installing database" mysql_install_db mysql_start_bg - debug "Deleting all users to avoid issues with master-slave configurations..." + wait_for_mysql_access + # we delete existing users and create new ones with stricter access + # commands can still be executed until we restart or run 'flush privileges' + info "Configuring authentication" mysql_execute "mysql" <'mysql.sys'; EOF # slaves do not need to configure users if [[ -z "$DB_REPLICATION_MODE" ]] || [[ "$DB_REPLICATION_MODE" = "master" ]]; then if [[ "$DB_REPLICATION_MODE" = "master" ]]; then - debug "Starting replication..." - if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then - echo "RESET MASTER;" | "$DB_BINDIR/mysql" --defaults-file="$DB_CONFDIR/my.cnf" -N -u root - else - echo "RESET MASTER;" | "$DB_BINDIR/mysql" --defaults-file="$DB_CONFDIR/my.cnf" -N -u root >/dev/null 2>&1 - fi + debug "Starting replication" + echo "RESET MASTER;" | debug_execute "$DB_BINDIR/mysql" --defaults-file="$DB_CONFDIR/my.cnf" -N -u root fi mysql_ensure_root_user_exists "$DB_ROOT_USER" "$DB_ROOT_PASSWORD" mysql_ensure_user_not_exists "" # ensure unknown user does not exist mysql_ensure_optional_database_exists "$DB_DATABASE" "$DB_USER" "$DB_PASSWORD" + [[ -n "$DB_ROOT_PASSWORD" ]] && export ROOT_AUTH_ENABLED="yes" fi - [[ -n "$(get_master_env_var_value ROOT_PASSWORD)" ]] && export ROOT_AUTH_ENABLED="yes" - # configure replication mode [[ -n "$DB_REPLICATION_MODE" ]] && mysql_configure_replication - if [[ "$DB_FLAVOR" = "mysql" ]]; then - mysql_upgrade - else - local args=(mysql) - if [[ -z "$DB_REPLICATION_MODE" ]] || [[ "$DB_REPLICATION_MODE" = "master" ]]; then - args+=("$DB_ROOT_USER" "$DB_ROOT_PASSWORD") - fi - debug "Flushing privileges..." - mysql_execute "${args[@]}" </dev/null 2>&1 - fi + debug_execute "$DB_BINDIR/mysql" "${args[@]}" } ######################## @@ -505,11 +509,7 @@ mysql_remote_execute() { local args=("-N" "-h" "$hostname" "-P" "$port" "-u" "$user" "--connect-timeout=5" "$db") [[ -n "$pass" ]] && args+=("-p$pass") - if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then - "$DB_BINDIR/mysql" "${args[@]}" - else - "$DB_BINDIR/mysql" "${args[@]}" >/dev/null 2>&1 - fi + debug_execute "$DB_BINDIR/mysql" "${args[@]}" } ######################## @@ -541,8 +541,42 @@ is_mysql_running() { # Returns: # None ######################### +mysql_start_bg() { + local flags=("--defaults-file=${DB_BASEDIR}/conf/my.cnf" "--basedir=${DB_BASEDIR}" "--datadir=${DB_DATADIR}" "--socket=$DB_TMPDIR/mysql.sock" "--port=$DB_PORT_NUMBER") + [[ -z "${DB_EXTRA_FLAGS:-}" ]] || flags+=("${DB_EXTRA_FLAGS[@]}") + am_i_root && flags+=("--user=$DB_DAEMON_USER") + # the slave should only start in run.sh, elseways user credentials would be needed for any connection + flags+=("--skip-slave-start") + flags+=("$@") + + is_mysql_running && return + + info "Starting $DB_FLAVOR in background" + debug_execute "${DB_SBINDIR}/mysqld" "${flags[@]}" & + + # we cannot use wait_for_mysql_access here as mysql_upgrade for MySQL >=8 depends on this command + # users are not configured on slave nodes during initialization due to --skip-slave-start + wait_for_mysql +} + ######################## -# Starts MySQL/MariaDB in the background and waits until it's ready +# Wait for MySQL/MariaDB to be running +# Globals: +# DB_TMPDIR +# Arguments: +# None +# Returns: +# Boolean +######################### +wait_for_mysql() { + local pid + while ! is_mysql_running; do + sleep 1 + done +} + +######################## +# Wait for MySQL/MariaDB to be ready for accepting connections # Globals: # DB_* # Arguments: @@ -550,22 +584,7 @@ is_mysql_running() { # Returns: # None ######################### -mysql_start_bg() { - local flags=("--defaults-file=${DB_BASEDIR}/conf/my.cnf" "--basedir=${DB_BASEDIR}" "--datadir=${DB_DATADIR}" "--socket=$DB_TMPDIR/mysql.sock" "--port=$DB_PORT_NUMBER") - [[ -z "${DB_EXTRA_FLAGS:-}" ]] || flags=("${flags[@]}" "${DB_EXTRA_FLAGS[@]}") - [[ -z "${DB_FORCE_UPGRADE:-}" ]] || flags=("${flags[@]}" "--upgrade=FORCE") - am_i_root && flags=("${flags[@]}" "--user=$DB_DAEMON_USER") - - debug "Starting $DB_FLAVOR in background..." - - is_mysql_running && return - - if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then - "${DB_SBINDIR}/mysqld" "${flags[@]}" & - else - "${DB_SBINDIR}/mysqld" "${flags[@]}" >/dev/null 2>&1 & - fi - +wait_for_mysql_access() { # wait until the server is up and answering queries. local args=("mysql" "root") is_boolean_yes "${ROOT_AUTH_ENABLED:-false}" && args+=("$(get_master_env_var_value ROOT_PASSWORD)") @@ -584,7 +603,9 @@ mysql_start_bg() { # None ######################### mysql_stop() { - info "Stopping $DB_FLAVOR..." + ! is_mysql_running && return + + info "Stopping $DB_FLAVOR" stop_service_using_pid "$DB_TMPDIR/mysqld.pid" } @@ -602,16 +623,11 @@ mysql_install_db() { local command="${DB_BINDIR}/mysql_install_db" local args=("--defaults-file=${DB_CONFDIR}/my.cnf" "--basedir=${DB_BASEDIR}" "--datadir=${DB_DATADIR}") am_i_root && args=("${args[@]}" "--user=$DB_DAEMON_USER") - debug "Installing database..." if [[ "$DB_FLAVOR" = "mysql" ]]; then command="${DB_BINDIR}/mysqld" args+=("--initialize-insecure") fi - if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then - $command "${args[@]}" - else - $command "${args[@]}" >/dev/null 2>&1 - fi + debug_execute "$command" "${args[@]}" } ######################## @@ -625,30 +641,17 @@ mysql_install_db() { # None ######################### mysql_upgrade() { - local args=("--defaults-file=${DB_CONFDIR}/my.cnf" "-u" "$DB_ROOT_USER") + local args=("--defaults-file=${DB_CONFDIR}/my.cnf" "-u" "$DB_ROOT_USER" "--force") local major_version - - major_version=$(get_sematic_version "$(mysql_get_version)" 1) - - debug "Running mysql_upgrade..." - + major_version="$(get_sematic_version "$(mysql_get_version)" 1)" + info "Running mysql_upgrade" if [[ "$DB_FLAVOR" = "mysql" ]] && [[ "$major_version" -ge "8" ]]; then mysql_stop - export DB_FORCE_UPGRADE=true - mysql_start_bg - unset DB_FORCE_UPGRADE + mysql_start_bg "--upgrade=FORCE" else - if [[ "$DB_FLAVOR" = "mysql" ]]; then - args+=("--force") - fi - if [[ -z "$DB_REPLICATION_MODE" ]] || [[ "$DB_REPLICATION_MODE" = "master" ]]; then - is_boolean_yes "${ROOT_AUTH_ENABLED:-false}" && args+=("-p$(get_master_env_var_value ROOT_PASSWORD)") - fi - if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then - "${DB_BINDIR}/mysql_upgrade" "${args[@]}" - else - "${DB_BINDIR}/mysql_upgrade" "${args[@]}" >/dev/null 2>&1 - fi + mysql_start_bg + is_boolean_yes "${ROOT_AUTH_ENABLED:-false}" && args+=("-p$(get_master_env_var_value ROOT_PASSWORD)") + debug_execute "${DB_BINDIR}/mysql_upgrade" "${args[@]}" fi } @@ -664,8 +667,8 @@ mysql_upgrade() { migrate_old_configuration() { local old_custom_conf_file="$DB_VOLUMEDIR/conf/my_custom.cnf" local custom_conf_file="$DB_CONFDIR/bitnami/my_custom.cnf" - debug "Persisted configuration detected. Migrating any existing 'my_custom.cnf' file to new location..." - warn "Custom configuration files won't be persisted any longer!" + debug "Persisted configuration detected. Migrating any existing 'my_custom.cnf' file to new location" + warn "Custom configuration files are not persisted any longer" if [[ -f "$old_custom_conf_file" ]]; then info "Adding old custom configuration to user configuration" echo "" >> "$custom_conf_file" @@ -694,11 +697,11 @@ mysql_ensure_user_exists() { local password="${2:-}" local hosts - debug "creating db user \'$user\'..." + debug "creating database user \'$user\'" mysql_execute "mysql" "$DB_ROOT_USER" "$DB_ROOT_PASSWORD" <