devstack-plugin-mariadb/devstack/lib/mariadb

72 lines
2.3 KiB
Bash
Executable File

#!/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';"
# Now update ``my.cnf`` for some local needs and restart the mysql service
# Change bind-address from localhost (127.0.0.1) to any (::) and
iniset -sudo $my_conf mysqld bind-address "$SERVICE_LISTEN_ADDRESS"
iniset -sudo $my_conf mysqld sql_mode STRICT_ALL_TABLES
iniset -sudo $my_conf mysqld default-storage-engine InnoDB
iniset -sudo $my_conf ignore_builtin_innodb
iniset -sudo $my_conf plugin_load innodb=ha_innodb.so
iniset -sudo $my_conf mysqld max_connections 1024
iniset -sudo $my_conf mysqld query_cache_type OFF
iniset -sudo $my_conf mysqld query_cache_size 0
if [[ "$DATABASE_QUERY_LOGGING" == "True" ]]; then
echo_summary "Enabling MySQL query logging"
slow_log=/var/log/mysql/mysql-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 {
# while ``.my.cnf`` is not needed for OpenStack to function, it is useful
# as it allows you to access the mysql databases via ``mysql nova`` instead
# of having to specify the username/password each time.
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
install_package mariadb-server
}
function stop_mariadb {
stop_service mysql
}