summaryrefslogtreecommitdiffstats
path: root/root-galera/usr/share/container-scripts/mysql/galera
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2018-03-17 21:07:38 +0100
committerSuren A. Chilingaryan <csa@suren.me>2018-03-17 21:07:38 +0100
commit14d10bc21087e3734d4e7ac15883c76d0cd19818 (patch)
tree02600a93e7849e9f9e4ab9399c1258ec36cc2273 /root-galera/usr/share/container-scripts/mysql/galera
downloadmysql-galera-14d10bc21087e3734d4e7ac15883c76d0cd19818.tar.gz
mysql-galera-14d10bc21087e3734d4e7ac15883c76d0cd19818.tar.bz2
mysql-galera-14d10bc21087e3734d4e7ac15883c76d0cd19818.tar.xz
mysql-galera-14d10bc21087e3734d4e7ac15883c76d0cd19818.zip
MySQL 5.7 with Galera (produced as combination of standard MySQL container and openshift-mariadb-galera by adfinis-sygroup)
Diffstat (limited to 'root-galera/usr/share/container-scripts/mysql/galera')
-rw-r--r--root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf4
-rwxr-xr-xroot-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh48
2 files changed, 52 insertions, 0 deletions
diff --git a/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf b/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf
new file mode 100644
index 0000000..5e9d444
--- /dev/null
+++ b/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf
@@ -0,0 +1,4 @@
+[mysqld]
+# By default every node is standalone
+wsrep_cluster_address=gcomm://
+wsrep_node_address=127.0.0.1
diff --git a/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh b/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh
new file mode 100755
index 0000000..05829a4
--- /dev/null
+++ b/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh
@@ -0,0 +1,48 @@
+#! /bin/bash
+
+# Copyright 2016 The Kubernetes Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This script writes out a mysql galera config using a list of newline seperated
+# peer DNS names it accepts through stdin.
+
+# /etc/mysql is assumed to be a shared volume so we can modify my.cnf as required
+# to keep the config up to date, without wrapping mysqld in a custom pid1.
+# The config location is intentionally not /etc/mysql/my.cnf because the
+# standard base image clobbers that location.
+CFG=/etc/my.cnf.d/cluster.cnf
+
+function join {
+ local IFS="$1"; shift; echo "$*";
+}
+
+HOSTNAME=$(hostname)
+while read -ra LINE; do
+ if [[ "${LINE}" == *"${HOSTNAME}"* ]]; then
+ MY_NAME=$LINE
+ fi
+ PEERS=("${PEERS[@]}" $LINE)
+done
+
+if [ "${#PEERS[@]}" = 1 ]; then
+ WSREP_CLUSTER_ADDRESS=""
+else
+ WSREP_CLUSTER_ADDRESS=$(join , "${PEERS[@]}")
+fi
+
+sed -i -e "s|^wsrep_node_address=.*$|wsrep_node_address=${MY_NAME}|" ${CFG}
+sed -i -e "s|^wsrep_cluster_address=.*$|wsrep_cluster_address=gcomm://${WSREP_CLUSTER_ADDRESS}|" ${CFG}
+
+# don't need a restart, we're just writing the conf in case there's an
+# unexpected restart on the node.