Devstack plugin to use mariadb on Ubuntu

Devstack uses mysql flavor by default on Ubuntu.
This plugin enforces MariaDB as the database backend.
This commit is contained in:
Rafael Folco 2016-05-16 20:14:57 +00:00
commit d1de0d4207
4 changed files with 120 additions and 0 deletions

13
README.rst Normal file
View File

@ -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``

55
devstack/lib/mariadb Executable file
View File

@ -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 <<EOF >$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
}

45
devstack/plugin.sh Executable file
View File

@ -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:

7
devstack/settings Normal file
View File

@ -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