diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2018-03-17 21:07:38 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2018-03-17 21:07:38 +0100 |
commit | 14d10bc21087e3734d4e7ac15883c76d0cd19818 (patch) | |
tree | 02600a93e7849e9f9e4ab9399c1258ec36cc2273 /root-galera/usr/bin/run-mysqld-galera | |
download | mysql-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/bin/run-mysqld-galera')
-rwxr-xr-x | root-galera/usr/bin/run-mysqld-galera | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/root-galera/usr/bin/run-mysqld-galera b/root-galera/usr/bin/run-mysqld-galera new file mode 100755 index 0000000..f1a0d76 --- /dev/null +++ b/root-galera/usr/bin/run-mysqld-galera @@ -0,0 +1,64 @@ +#!/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/cluster.cnf | cat) + if [ -n "$no_cluster" ]; then + log_info "No cluster configured, recovering from failure..." + log_info "Allowing recovery in $MYSQL_DATADIR/grastate.dat" + 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 - mysqld --defaults-file=$MYSQL_DEFAULTS_FILE $mysql_extra_opts $@" + +exec ${MYSQL_PREFIX}/libexec/mysqld --defaults-file=$MYSQL_DEFAULTS_FILE $mysql_extra_opts "$@" 2>&1 |