commit d1de0d420718ee9b68f1c5a96c259c2fa5b48493 Author: Rafael Folco Date: Mon May 16 20:14:57 2016 +0000 Devstack plugin to use mariadb on Ubuntu Devstack uses mysql flavor by default on Ubuntu. This plugin enforces MariaDB as the database backend. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..e5f9626 --- /dev/null +++ b/README.rst @@ -0,0 +1,13 @@ +====================== + Enabling in Devstack +====================== + +1. Download DevStack + +2. Add this repo as an external repository:: + + > cat local.conf + [[local|localrc]] + enable_plugin mariadb https://github.com/rafaelfolco/devstack-plugin-mariadb + +3. run ``stack.sh`` diff --git a/devstack/lib/mariadb b/devstack/lib/mariadb new file mode 100755 index 0000000..66d6427 --- /dev/null +++ b/devstack/lib/mariadb @@ -0,0 +1,55 @@ +#!/bin/bash + +# MariaDB overrides for lib/databases/mysql + +function cleanup_mariadb { + stop_mariadb + apt_get purge -y mysql* mariadb* + sudo rm -rf /var/lib/mysql + sudo rm -rf /etc/mysql +} + +function configure_mariadb { + local my_conf mysql slow_log + echo_summary "Configuring and starting MariaDB" + + my_conf=/etc/mysql/my.cnf + mysql=mysql + + sudo mysql -uroot -hlocalhost -e "GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'%' identified by '$DATABASE_PASSWORD';" + if [[ "$DATABASE_QUERY_LOGGING" == "True" ]]; then + echo_summary "Enabling MySQL query logging" + slow_log=/var/log/mariadb/mariadb-slow.log + sudo sed -e '/log.slow.queries/d' \ + -e '/long.query.time/d' \ + -e '/log.queries.not.using.indexes/d' \ + -i $my_conf + # Turn on slow query log, log all queries (any query taking longer than + # 0 seconds) and log all non-indexed queries + iniset -sudo $my_conf mysqld slow-query-log 1 + iniset -sudo $my_conf mysqld slow-query-log-file $slow_log + iniset -sudo $my_conf mysqld long-query-time 0 + iniset -sudo $my_conf mysqld log-queries-not-using-indexes 1 + fi + restart_service $mysql +} + +function install_mariadb { + if [[ ! -e $HOME/.my.cnf ]]; then + cat <$HOME/.my.cnf +[client] +user=$DATABASE_USER +password=$DATABASE_PASSWORD +host=$MYSQL_HOST +EOF + chmod 0600 $HOME/.my.cnf + fi + if is_ubuntu; then + install_package mariadb-server + fi +} + +function stop_mariadb { + stop_service mysql +} + diff --git a/devstack/plugin.sh b/devstack/plugin.sh new file mode 100755 index 0000000..0e26ed9 --- /dev/null +++ b/devstack/plugin.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# devstack/plugin.sh +# Setup MariaDB as database backend for Devstack + + +if is_service_enabled mysql && is_ubuntu; then + + function cleanup_database_mysql { + cleanup_mariadb + } + + function configure_database_mysql { + configure_mariadb + } + + function install_database_mysql { + install_mariadb + } + + if [[ "$1" == "stack" && "$2" == "install" ]]; then + echo_summary "Installing MariaDB" + install_mariadb + elif [[ "$1" == "stack" && "$2" == "pre-install" ]]; then + # nothing needed here + : + elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then + echo_summary "Configuring MariaDB" + configure_mariadb + fi + if [[ "$1" == "unstack" ]]; then + echo_summary "Stopping MariaDB" + stop_mariadb + fi + if [[ "$1" == "clean" ]]; then + echo_summary "Removing MariaDB" + cleanup_mariadb + fi +else + die $LINENO "MariaDB plugin requires mysql service enabled and ubuntu." +fi + +## Local variables: +## mode: shell-script +## End: diff --git a/devstack/settings b/devstack/settings new file mode 100644 index 0000000..ee05c0b --- /dev/null +++ b/devstack/settings @@ -0,0 +1,7 @@ +# MariaDB on Ubuntu uses unix_socket IPC for root auth (localhost!=127.0.0.1) +DATABASE_USER=stack + +# MARIADB_PLUGIN_DIR contains the path to devstack-plugin-glusterfs/devstack directory +MARIADB_PLUGIN_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})) + +source $MARIADB_PLUGIN_DIR/lib/mariadb