From 823f5325df405286024cdf2a985732baabc0981f Mon Sep 17 00:00:00 2001
From: "Suren A. Chilingaryan" <csa@suren.me>
Date: Wed, 21 Mar 2018 22:00:26 +0100
Subject: Add Dockerfile for simple Master/Slave replication and add more
 parametrization

---
 root-galera/usr/bin/peer-finder                    | Bin 2214569 -> 0 bytes
 root-galera/usr/bin/run-mysqld-galera              |  69 ----------------
 root-galera/usr/bin/run-mysqld-manager             |  90 ---------------------
 .../share/container-scripts/mysql/galera-common.sh |  61 --------------
 .../mysql/galera-init/60-galera-config.sh          |   6 --
 .../mysql/galera-init/galera.cnf.template          |  21 -----
 .../mysql/galera-init/galera.cnf.template.maria    |  17 ----
 .../container-scripts/mysql/galera/cluster.cnf     |   4 -
 .../mysql/galera/configure-galera.sh               |  48 -----------
 .../mysql/init/50-galera-passwd-change.sh          |  14 ----
 .../container-scripts/mysql/init/51-extradb.sh     |  14 ----
 .../share/container-scripts/mysql/init/52-super.sh |  12 ---
 .../share/container-scripts/mysql/init/53-pma.sh   |  26 ------
 13 files changed, 382 deletions(-)
 delete mode 100755 root-galera/usr/bin/peer-finder
 delete mode 100755 root-galera/usr/bin/run-mysqld-galera
 delete mode 100755 root-galera/usr/bin/run-mysqld-manager
 delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera-common.sh
 delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera-init/60-galera-config.sh
 delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template
 delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria
 delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf
 delete mode 100755 root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh
 delete mode 100644 root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh
 delete mode 100644 root-galera/usr/share/container-scripts/mysql/init/51-extradb.sh
 delete mode 100644 root-galera/usr/share/container-scripts/mysql/init/52-super.sh
 delete mode 100644 root-galera/usr/share/container-scripts/mysql/init/53-pma.sh

(limited to 'root-galera/usr')

diff --git a/root-galera/usr/bin/peer-finder b/root-galera/usr/bin/peer-finder
deleted file mode 100755
index af52ee1..0000000
Binary files a/root-galera/usr/bin/peer-finder and /dev/null differ
diff --git a/root-galera/usr/bin/run-mysqld-galera b/root-galera/usr/bin/run-mysqld-galera
deleted file mode 100755
index 9ff6c26..0000000
--- a/root-galera/usr/bin/run-mysqld-galera
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/bash
-
-if [ -v POD_NAMESPACE ]; then
-        cp "${CONTAINER_SCRIPTS_PATH}/galera/cluster.cnf" /etc/my.cnf.d/
-
-        # Is running in Kubernetes/OpenShift, so find all other pods
-        # belonging to the namespace
-        echo "Galera: Finding peers"
-        [ -v MYSQL_GALERA_CLUSTER ] || MYSQL_GALERA_CLUSTER="$(hostname -f | cut -d'.' -f2)"
-        K8S_SVC_NAME=${MYSQL_GALERA_CLUSTER}
-        echo "Using service name: ${K8S_SVC_NAME}"
-        /usr/bin/peer-finder -on-start="${CONTAINER_SCRIPTS_PATH}/galera/configure-galera.sh" -service=${K8S_SVC_NAME}
-else
-        echo "POD_NAMESPACE not set, spin up single node"
-fi
-
-
-export_vars=$(cgroup-limits); export $export_vars
-source ${CONTAINER_SCRIPTS_PATH}/galera-common.sh
-set -eu
-if [[ -v DEBUG_IGNORE_SCRIPT_FAILURES ]]; then
-  set +e
-fi
-
-export_setting_variables
-
-log_volume_info $MYSQL_DATADIR
-
-# pre-init files
-process_extending_files ${APP_DATA}/mysql-pre-init/ ${CONTAINER_SCRIPTS_PATH}/pre-init/
-
-mysql_extra_opts=""
-if [ ! -d "$MYSQL_DATADIR/mysql" ]; then
-  initialize_galera_database "$@"
-
-  # galera files
-  process_extending_files ${APP_DATA}/mysql-galera-init/ ${CONTAINER_SCRIPTS_PATH}/galera-init/
-
-  # init files
-  process_extending_files ${APP_DATA}/mysql-init/ ${CONTAINER_SCRIPTS_PATH}/init/
-
-  # Restart the MySQL server with public IP bindings
-  shutdown_local_mysql
-else
-    no_cluster=$(grep -P "gcomm://$" ${MYSQL_DEFAULTS_FILE}.d/cluster.cnf | cat)
-    if [ -n "$no_cluster" ]; then
-        log_info "Configuration: $MYSQL_DEFAULTS_FILE"
-        log_info "No cluster is configured yet, trying to recover from failure..."
-        log_info "Allowing recovery in $MYSQL_DATADIR/grastate.dat"
-        sed -i'' 's/safe_to_bootstrap:.*/safe_to_bootstrap: 1/' $MYSQL_DATADIR/grastate.dat
-#        This seems unneeded
-#        mysql_extra_opts="--wsrep-new-cluster"
-    else
-        log_info "Configuration: $MYSQL_DEFAULTS_FILE"
-        log_info "Cluster is configured. Trying to join..."
-    fi
-
-  # galera files
-  process_extending_files ${APP_DATA}/mysql-galera-init/ ${CONTAINER_SCRIPTS_PATH}/galera-init/
-
-#  I guess we can't do that once cluster is existing...
-#  start_local_mysql --wsrep-on=OFF --wsrep-provider=none  "$@"
-fi
-
-unset_env_vars
-log_volume_info $MYSQL_DATADIR
-log_info "Running final exec - mysqld --defaults-file=$MYSQL_DEFAULTS_FILE $mysql_extra_opts $@"
-
-exec ${MYSQL_PREFIX}/libexec/mysqld --defaults-file=$MYSQL_DEFAULTS_FILE $mysql_extra_opts "$@" 2>&1
diff --git a/root-galera/usr/bin/run-mysqld-manager b/root-galera/usr/bin/run-mysqld-manager
deleted file mode 100755
index 878338a..0000000
--- a/root-galera/usr/bin/run-mysqld-manager
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/bin/bash
-
-export TERM=xterm
-function display_container_header {
-    echo "+====================================================="
-    echo "| Container   : $HOSTNAME"
-    echo "| OS          : $(</etc/redhat-release)"
-    echo "| kubernetes  : $KUBERNETES_SERVICE_HOST"
-    echo "| user        : $(whoami)"
-    echo "| home        : $HOME"
-    echo "+====================================================="
-}
-
-function start_service {
-    echo "+====================================================="
-    echo "| Container $HOSTNAME is now RUNNING"
-    echo "+====================================================="
-    while true
-    do
-      echo /usr/bin/peer-finder -on-start="${CONTAINER_SCRIPTS_PATH}/galera/configure-galera.sh" -service=${K8S_SVC_NAME}
-      echo ${MYSQL_PREFIX}/libexec/mysqld --defaults-file=$MYSQL_DEFAULTS_FILE $mysql_extra_opts "$@"
-      echo "live... (next try in 1 hour)" & sleep 3600
-    done
-}
-
-
-if [ -v POD_NAMESPACE ]; then
-        cp "${CONTAINER_SCRIPTS_PATH}/galera/cluster.cnf" /etc/my.cnf.d/
-
-        # Is running in Kubernetes/OpenShift, so find all other pods
-        # belonging to the namespace
-        echo "Galera: Skip finding peers to prevent failures due to failed cluster"
-        [ -v MYSQL_GALERA_CLUSTER ] || MYSQL_GALERA_CLUSTER="$(hostname -f | cut -d'.' -f2)"
-        K8S_SVC_NAME=${MYSQL_GALERA_CLUSTER}
-        echo "Using service name: ${K8S_SVC_NAME}"
-        echo /usr/bin/peer-finder -on-start="${CONTAINER_SCRIPTS_PATH}/galera/configure-galera.sh" -service=${K8S_SVC_NAME}
-else
-        echo "POD_NAMESPACE not set, spin up single node"
-fi
-
-
-export_vars=$(cgroup-limits); export $export_vars
-source ${CONTAINER_SCRIPTS_PATH}/galera-common.sh
-set -eu
-if [[ -v DEBUG_IGNORE_SCRIPT_FAILURES ]]; then
-  set +e
-fi
-
-export_setting_variables
-
-log_volume_info $MYSQL_DATADIR
-
-# pre-init files
-process_extending_files ${APP_DATA}/mysql-pre-init/ ${CONTAINER_SCRIPTS_PATH}/pre-init/
-
-mysql_extra_opts=""
-if [ ! -d "$MYSQL_DATADIR/mysql" ]; then
-  initialize_galera_database "$@"
-
-  # galera files
-  process_extending_files ${APP_DATA}/mysql-galera-init/ ${CONTAINER_SCRIPTS_PATH}/galera-init/
-
-  # init files
-  process_extending_files ${APP_DATA}/mysql-init/ ${CONTAINER_SCRIPTS_PATH}/init/
-
-  # Restart the MySQL server with public IP bindings
-  shutdown_local_mysql
-else
-    no_cluster=$(grep -P "gcomm://$" | cat)
-    if [ -n "$no_cluster" ]; then
-        echo "No cluster configured, recovering from failure..."
-        sed -i'' -e  's/safe_to_bootstrap:.*/safe_to_bootstrap: 1/' $MYSQL_DATADIR/grastate.dat
-        mysql_extra_opts="--wsrep-new-cluster"
-    fi
-
-  # galera files
-  process_extending_files ${APP_DATA}/mysql-galera-init/ ${CONTAINER_SCRIPTS_PATH}/galera-init/
-
-#  I guess we can't do that once cluster is existing...
-#  start_local_mysql --wsrep-on=OFF --wsrep-provider=none  "$@"
-fi
-
-unset_env_vars
-log_volume_info $MYSQL_DATADIR
-log_info 'Running final exec -- Only MySQL server logs after this point'
-
-
-echo ${MYSQL_PREFIX}/libexec/mysqld --defaults-file=$MYSQL_DEFAULTS_FILE $mysql_extra_opts "$@"
-display_container_header
-start_service
diff --git a/root-galera/usr/share/container-scripts/mysql/galera-common.sh b/root-galera/usr/share/container-scripts/mysql/galera-common.sh
deleted file mode 100644
index b4d90e5..0000000
--- a/root-galera/usr/share/container-scripts/mysql/galera-common.sh
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/bin/bash
-
-source ${CONTAINER_SCRIPTS_PATH}/common.sh
-
-# Initialize the MySQL database (create user accounts and the initial database)
-function initialize_galera_database() {
-  log_info 'Initializing database ...'
-  if [[ "$MYSQL_VERSION" < "5.7" ]] ; then
-    # Using --rpm since we need mysql_install_db behaves as in RPM
-    log_info 'Running mysql_install_db ...'
-    mysql_install_db --rpm --datadir=$MYSQL_DATADIR
-  else
-    log_info "Running mysqld --initialize-insecure ..."
-    ${MYSQL_PREFIX}/libexec/mysqld --wsrep-on=OFF --wsrep-provider=none  --initialize-insecure --datadir=$MYSQL_DATADIR --ignore-db-dir=lost+found "$@"
-  fi
-  
-  start_local_mysql --wsrep-on=OFF --wsrep-provider=none  "$@"
-
-  if [ -v MYSQL_RUNNING_AS_SLAVE ]; then
-    log_info 'Initialization finished'
-    return 0
-  fi
-
-  # Do not care what option is compulsory here, just create what is specified
-  if [ -v MYSQL_USER ]; then
-    log_info "Creating user specified by MYSQL_USER (${MYSQL_USER}) ..."
-mysql $mysql_flags <<EOSQL
-    CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';
-EOSQL
-  fi
-
-  if [ -v MYSQL_DATABASE ]; then
-    log_info "Creating database ${MYSQL_DATABASE} ..."
-    mysqladmin $admin_flags create "${MYSQL_DATABASE}"
-    if [ -v MYSQL_USER ]; then
-      log_info "Granting privileges to user ${MYSQL_USER} for ${MYSQL_DATABASE} ..."
-mysql $mysql_flags <<EOSQL
-      GRANT ALL ON \`${MYSQL_DATABASE}\`.* TO '${MYSQL_USER}'@'%' ;
-      FLUSH PRIVILEGES ;
-EOSQL
-    fi
-  fi
-
-  if [ -v MYSQL_ROOT_PASSWORD ]; then
-    log_info "Setting password for MySQL root user ..."
-    # for 5.6 and lower we use the trick that GRANT creates a user if not exists
-    # because IF NOT EXISTS clause does not exist in that versions yet
-    if [[ "$MYSQL_VERSION" > "5.6" ]] ; then
-      mysql $mysql_flags <<EOSQL
-        CREATE USER IF NOT EXISTS 'root'@'%';
-EOSQL
-    fi
-mysql $mysql_flags <<EOSQL
-    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' WITH GRANT OPTION;
-EOSQL
-  fi
-  log_info 'Initialization finished'
-
-  # remember that the database was just initialized, it may be needed on other places
-  export MYSQL_DATADIR_FIRST_INIT=true
-}
diff --git a/root-galera/usr/share/container-scripts/mysql/galera-init/60-galera-config.sh b/root-galera/usr/share/container-scripts/mysql/galera-init/60-galera-config.sh
deleted file mode 100644
index e6cce5a..0000000
--- a/root-galera/usr/share/container-scripts/mysql/galera-init/60-galera-config.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ -v POD_NAMESPACE ]; then
-    [ -v MYSQL_GALERA_CLUSTER ] || export MYSQL_GALERA_CLUSTER="$(hostname -f | cut -d'.' -f2)"
-
-    log_info 'Processing basic Galera configuration files ...'
-    envsubst < ${CONTAINER_SCRIPTS_PATH}/galera-init/galera.cnf.template > /etc/my.cnf.d/galera.cnf
-fi
diff --git a/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template b/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template
deleted file mode 100644
index b45dc85..0000000
--- a/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template
+++ /dev/null
@@ -1,21 +0,0 @@
-[mysqld]
-wsrep_on = ON
-wsrep_provider = /usr/lib64/galera-3/libgalera_smm.so
-wsrep_sst_auth=${MYSQL_GALERA_USER}:${MYSQL_GALERA_PASSWORD}
-wsrep_cluster_name=${MYSQL_GALERA_CLUSTER}
-#wsrep_provider_options="gcache.size=500M; gcache.page_size=500M"
-wsrep_sst_method = xtrabackup-v2
-default_storage_engine = innodb
-binlog_format = row
-
-#MySQL tuning
-#max_threads = 128
-#key_buffer_size = 1024K
-#sort_buffer_size = 1024K
-#read_buffer_size = 1024K
-
-# Performance settings
-innodb_autoinc_lock_mode = 2
-innodb_flush_log_at_trx_commit = 0
-query_cache_size = 0
-query_cache_type = 0
diff --git a/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria b/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria
deleted file mode 100644
index 3adbf58..0000000
--- a/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria
+++ /dev/null
@@ -1,17 +0,0 @@
-[galera]
-wsrep_on = ON
-wsrep_provider = /usr/lib64/galera/libgalera_smm.so
-wsrep_sst_method = xtrabackup-v2
-default_storage_engine = innodb
-binlog_format = row
-innodb_autoinc_lock_mode = 2
-innodb_flush_log_at_trx_commit = 0
-query_cache_size = 0
-query_cache_type = 0
-
-wsrep_sst_auth=${MYSQL_GALERA_USER}:${MYSQL_GALERA_PASSWORD}
-wsrep_cluster_name=${MYSQL_GALERA_CLUSTER}
-
-# 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/cluster.cnf b/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf
deleted file mode 100644
index 5e9d444..0000000
--- a/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf
+++ /dev/null
@@ -1,4 +0,0 @@
-[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
deleted file mode 100755
index 05829a4..0000000
--- a/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#! /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.
diff --git a/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh b/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh
deleted file mode 100644
index 2844d5f..0000000
--- a/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/bash
-
-password_change() {
-mysql $mysql_flags <<EOSQL
-    CREATE USER IF NOT EXISTS '${MYSQL_GALERA_USER}'@'localhost';
-    SET PASSWORD FOR '${MYSQL_GALERA_USER}'@'localhost' = PASSWORD('${MYSQL_GALERA_PASSWORD}');
-    GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '${MYSQL_GALERA_USER}'@'localhost';
-    UPDATE mysql.user SET Super_Priv='Y', Process_priv='Y' WHERE user='${MYSQL_GALERA_USER}' AND host='localhost';
-    FLUSH PRIVILEGES;
-EOSQL
-}
-
-password_change
-unset -f password_change
diff --git a/root-galera/usr/share/container-scripts/mysql/init/51-extradb.sh b/root-galera/usr/share/container-scripts/mysql/init/51-extradb.sh
deleted file mode 100644
index c047265..0000000
--- a/root-galera/usr/share/container-scripts/mysql/init/51-extradb.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-extradb() {
-for db in "$MYSQL_EXTRADB"; do
-mysql $mysql_flags <<EOSQL
-      GRANT ALL ON \`${db}\`.* TO '${MYSQL_USER}'@'%' ;
-      FLUSH PRIVILEGES ;
-EOSQL
-done;
-}
-
-if [ -v MYSQL_EXTRADB ]; then 
-    extradb
-fi
-
-unset -f extradb
diff --git a/root-galera/usr/share/container-scripts/mysql/init/52-super.sh b/root-galera/usr/share/container-scripts/mysql/init/52-super.sh
deleted file mode 100644
index 9e49151..0000000
--- a/root-galera/usr/share/container-scripts/mysql/init/52-super.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-set_super() {
-mysql $mysql_flags <<EOSQL
-    UPDATE mysql.user SET Super_Priv='Y' WHERE user='${MYSQL_USER}' AND host='%';
-    FLUSH PRIVILEGES;
-EOSQL
-}
-
-if [ -v MYSQL_USER_PRIV_SUPER ]; then 
-    set_super
-fi
-
-unset -f set_super
diff --git a/root-galera/usr/share/container-scripts/mysql/init/53-pma.sh b/root-galera/usr/share/container-scripts/mysql/init/53-pma.sh
deleted file mode 100644
index 5644b8f..0000000
--- a/root-galera/usr/share/container-scripts/mysql/init/53-pma.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-set_pma() {
-mysql $mysql_flags <<EOSQL
-    CREATE USER IF NOT EXISTS 'pma'@'%' IDENTIFIED BY '${MYSQL_PMA_PASSWORD}';
-    ALTER USER 'pma'@'%' IDENTIFIED BY '${MYSQL_PMA_PASSWORD}';
-    
-    GRANT USAGE ON mysql.* TO 'pma'@'%';
-    GRANT SELECT (
-        Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv,
-        Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv,
-        File_priv, Grant_priv, References_priv, Index_priv, Alter_priv,
-        Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv,
-        Execute_priv, Repl_slave_priv, Repl_client_priv
-    ) ON mysql.user TO 'pma'@'%';
-
-    GRANT SELECT ON mysql.db TO 'pma'@'%';
-    #GRANT SELECT ON mysql.host TO 'pma'@'%';
-    GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON mysql.tables_priv TO 'pma'@'%';
-    GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'%';
-EOSQL
-}
-
-if [ -v MYSQL_PMA_PASSWORD ]; then 
-    set_pma
-fi
-
-unset -f set_pma
-- 
cgit v1.2.3