diff options
Diffstat (limited to 'mysql/root-galera/usr/bin')
-rwxr-xr-x | mysql/root-galera/usr/bin/peer-finder | bin | 0 -> 2214569 bytes | |||
-rwxr-xr-x | mysql/root-galera/usr/bin/run-mysqld-galera | 71 | ||||
-rwxr-xr-x | mysql/root-galera/usr/bin/run-mysqld-manager | 91 |
3 files changed, 162 insertions, 0 deletions
diff --git a/mysql/root-galera/usr/bin/peer-finder b/mysql/root-galera/usr/bin/peer-finder Binary files differnew file mode 100755 index 0000000..af52ee1 --- /dev/null +++ b/mysql/root-galera/usr/bin/peer-finder diff --git a/mysql/root-galera/usr/bin/run-mysqld-galera b/mysql/root-galera/usr/bin/run-mysqld-galera new file mode 100755 index 0000000..1890209 --- /dev/null +++ b/mysql/root-galera/usr/bin/run-mysqld-galera @@ -0,0 +1,71 @@ +#!/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" -a ! -d "$MYSQL_DATADIR/.sst" ]; 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" +# This seems a bad idea. If another pod is marked safe to bootstrap we may end up in conflict, I guess.... +# Keep it manual for now +# 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/mysql/root-galera/usr/bin/run-mysqld-manager b/mysql/root-galera/usr/bin/run-mysqld-manager new file mode 100755 index 0000000..91f3c9c --- /dev/null +++ b/mysql/root-galera/usr/bin/run-mysqld-manager @@ -0,0 +1,91 @@ +#!/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" -a ! -d "$MYSQL_DATADIR/.sst" ]; 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 |