From d54a1c6869653c4af1d0dbd76e31b20879c675b5 Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Tue, 10 Sep 2019 12:05:06 +0200 Subject: [PATCH] Add possibility to configure manually MYSQL_SERVICE_NAME This variable can be now set in Devstack's config file and in such case Devstack will not set it automatically to value most likely correct for the distro. By default this value is empty string and in such case Devstack will work in exactly same way as it was before this patch and will determine automatically what name should be used there. In addition in case of Ubuntu package $MYSQL_SERVICE_NAME-server will be now installed instead of mysql-server always. This will allow to easy configure e.g. CI job which will run using Mariadb instead of Mysql on Ubuntu. Change-Id: I25af0b54ad235b08c6c399b4125c737acf57ee2e --- lib/databases/mysql | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/lib/databases/mysql b/lib/databases/mysql index 4d0f5f3e45..4e3cc72bdb 100644 --- a/lib/databases/mysql +++ b/lib/databases/mysql @@ -15,15 +15,17 @@ MYSQL_DRIVER=${MYSQL_DRIVER:-PyMySQL} register_database mysql -MYSQL_SERVICE_NAME=mysql -if is_fedora && ! is_oraclelinux; then - MYSQL_SERVICE_NAME=mariadb -elif is_suse && systemctl list-unit-files | grep -q 'mariadb\.service'; then - # Older mariadb packages on SLES 12 provided mysql.service. The - # newer ones on SLES 12 and 15 use mariadb.service; they also - # provide a mysql.service symlink for backwards-compatibility, but - # let's not rely on that. - MYSQL_SERVICE_NAME=mariadb +if [[ -z "$MYSQL_SERVICE_NAME" ]]; then + MYSQL_SERVICE_NAME=mysql + if is_fedora && ! is_oraclelinux; then + MYSQL_SERVICE_NAME=mariadb + elif is_suse && systemctl list-unit-files | grep -q 'mariadb\.service'; then + # Older mariadb packages on SLES 12 provided mysql.service. The + # newer ones on SLES 12 and 15 use mariadb.service; they also + # provide a mysql.service symlink for backwards-compatibility, but + # let's not rely on that. + MYSQL_SERVICE_NAME=mariadb + fi fi # Functions @@ -92,8 +94,23 @@ function configure_database_mysql { # because the package might have been installed already. sudo mysqladmin -u root password $DATABASE_PASSWORD || true + # In case of Mariadb, giving hostname in arguments causes permission + # problems as it expects connection through socket + if is_ubuntu && [ "$MYSQL_SERVICE_NAME" == "mariadb" ]; then + local cmd_args="-uroot -p$DATABASE_PASSWORD " + else + local cmd_args="-uroot -p$DATABASE_PASSWORD -h127.0.0.1 " + fi + + # In mariadb e.g. on Ubuntu socket plugin is used for authentication + # as root so it works only as sudo. To restore old "mysql like" behaviour, + # we need to change auth plugin for root user + if [ "$MYSQL_SERVICE_NAME" == "mariadb" ]; then + sudo mysql $cmd_args -e "UPDATE mysql.user SET plugin='' WHERE user='$DATABASE_USER' AND host='localhost';" + sudo mysql $cmd_args -e "FLUSH PRIVILEGES;" + fi # Update the DB to give user '$DATABASE_USER'@'%' full control of the all databases: - sudo mysql -uroot -p$DATABASE_PASSWORD -h127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'%' identified by '$DATABASE_PASSWORD';" + sudo mysql $cmd_args -e "GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'%' identified by '$DATABASE_PASSWORD';" # Now update ``my.cnf`` for some local needs and restart the mysql service @@ -148,8 +165,11 @@ MYSQL_PRESEED [client] user=$DATABASE_USER password=$DATABASE_PASSWORD -host=$MYSQL_HOST EOF + + if ! is_ubuntu || [ "$MYSQL_SERVICE_NAME" != "mariadb" ]; then + echo "host=$MYSQL_HOST" >> $HOME/.my.cnf + fi chmod 0600 $HOME/.my.cnf fi # Install mysql-server @@ -159,7 +179,7 @@ EOF install_package mariadb-server sudo systemctl enable $MYSQL_SERVICE_NAME elif is_ubuntu; then - install_package mysql-server + install_package $MYSQL_SERVICE_NAME-server else exit_distro_not_supported "mysql installation" fi