diff --git a/elements/mariadb/README.md b/elements/mariadb/README.md new file mode 100644 index 000000000..50b4b456d --- /dev/null +++ b/elements/mariadb/README.md @@ -0,0 +1,5 @@ +Installs MariaDB with galera + +Mysql and mariadb elements are very similar so both depend on mysql-common +element which contains shared logic. See mysql-common for more details about +mysql setup. diff --git a/elements/mariadb/element-deps b/elements/mariadb/element-deps new file mode 100644 index 000000000..6de744a69 --- /dev/null +++ b/elements/mariadb/element-deps @@ -0,0 +1,2 @@ +mariadb-dev +mysql-common diff --git a/elements/mariadb/element-provides b/elements/mariadb/element-provides new file mode 100644 index 000000000..0eaebf127 --- /dev/null +++ b/elements/mariadb/element-provides @@ -0,0 +1 @@ +mysql diff --git a/elements/mariadb/install.d/10-mariadb b/elements/mariadb/install.d/10-mariadb new file mode 100755 index 000000000..19e613aa2 --- /dev/null +++ b/elements/mariadb/install.d/10-mariadb @@ -0,0 +1,36 @@ +#!/bin/bash + +# Install controller base requiered packages + +set -e +set -o xtrace + +if [ "$(dib-init-system)" = "upstart" ] ; then + install $(dirname $0)/mysql-set-server-id.upstart /etc/init/mysql-set-server-id.conf +else + echo WARNING: server-id will not be set on systems that boot this image! +fi + +install-packages sysstat mytop python-mysqldb mariadb-galera-server mariadb-client galera + +# Templates write the configs into /mnt/state. However, MySQL makes it very +# difficult not to use this as the directory for configs. +rm -rf /etc/mysql +ln -s /mnt/state/etc/mysql /etc/mysql +if [ -e /etc/apparmor.d/usr.sbin.mysqld ] ; then + sed -i -e 's,/var/lib/mysql/,/mnt/state/var/lib/mysql/,g' /etc/apparmor.d/usr.sbin.mysqld + sed -i -e 's,/var/log/mysql/,/mnt/state/var/log/mysql/,g' /etc/apparmor.d/usr.sbin.mysqld + sed -i -e 's,/etc/mysql/,/mnt/state/etc/mysql/,g' /etc/apparmor.d/usr.sbin.mysqld +fi +if [ -e /etc/init/mysql.conf ]; then + sed -i -e 's,/var/lib/mysql/,/mnt/state/var/lib/mysql/,g' /etc/init/mysql.conf +fi +# Fedora/RHEL install /etc/my.cnf but we do not want any unmanaged configs +rm -f /etc/my.cnf +# On openSUSE /var/lib/mysql is not part of the mariadb packages. +[ -d /var/lib/mysql ] || install -d -o mysql -g root -m 0700 /var/lib/mysql +register-state-path /var/lib/mysql +# We need to setup the directory with appropriate permissions and then +# the first time we boot a particular state partition we rsync this in. +[ -d /var/log/mysql ] || install -d -o root -g mysql -m 0775 /var/log/mysql +register-state-path /var/log/mysql diff --git a/elements/mariadb/os-refresh-config/post-configure.d/40-mariadb b/elements/mariadb/os-refresh-config/post-configure.d/40-mariadb new file mode 100755 index 000000000..948bc2646 --- /dev/null +++ b/elements/mariadb/os-refresh-config/post-configure.d/40-mariadb @@ -0,0 +1,4 @@ +#!/bin/bash +set -eu + +os-svc-restart -n mysql diff --git a/elements/mariadb/os-refresh-config/pre-configure.d/50-mariadb-socket b/elements/mariadb/os-refresh-config/pre-configure.d/50-mariadb-socket new file mode 100755 index 000000000..f6b800cbb --- /dev/null +++ b/elements/mariadb/os-refresh-config/pre-configure.d/50-mariadb-socket @@ -0,0 +1,10 @@ +#!/bin/bash +set -eu + +# mariadb clients (from mariadb.org) expect the socket at +# /var/lib/mysql/mysql.sock +# +# mysql server is started from 51-init-openstack (reset-db script) - we need to +# create symlink to make sure reset-db will not fail +[ -d /var/lib/mysql ] || mkdir -p /var/lib/mysql +ln -sf /var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock