#!/bin/bash {{/* Copyright 2017 The Openstack-Helm 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. */}} set -xe # MariaDB 10.2.13 has a regression which breaks clustering, patch # around this for now if /usr/sbin/mysqld --version | grep --silent 10.2.13 ; then sed -i 's^LSOF_OUT=.*^LSOF_OUT=$(lsof -sTCP:LISTEN -i TCP:${PORT} -a -c nc -c socat -F c 2> /dev/null || :)^' /usr/bin/wsrep_sst_xtrabackup-v2 fi # Bootstrap database CLUSTER_INIT_ARGS="" CLUSTER_CONFIG_PATH=/etc/mysql/conf.d/10-cluster-config.cnf function exitWithManualRecovery() { UUID=$(sed -e 's/^.*uuid:[\ ,\t]*//' -e 'tx' -e 'd' -e ':x' /var/lib/mysql/grastate.dat) SEQNO=$(sed -e 's/^.*seqno:[\ ,\t]*//' -e 'tx' -e 'd' -e ':x' /var/lib/mysql/grastate.dat) cat >/dev/stderr < to force bootstrapping from the specified node. Remember to remove FORCE_RECOVERY after your nodes are fully recovered! You may lose data otherwise. You can ignore this message and wait for the next restart if at least one node started without errors. EOF exit 1 } # Construct cluster config MEMBERS="" for i in $(seq 1 ${MARIADB_REPLICAS}); do if [ "$i" -eq "1" ]; then NUM="0" else NUM="$(expr $i - 1)" fi CANDIDATE_POD="${SERVICE_NAME}-$NUM.$(hostname -d)" if [ "x${CANDIDATE_POD}" != "x${POD_NAME}.$(hostname -d)" ]; then if [ -n "${MEMBERS}" ]; then MEMBERS+=, fi MEMBERS+="${CANDIDATE_POD}:${WSREP_PORT}" fi done echo "Writing cluster config for ${POD_NAME} to ${CLUSTER_CONFIG_PATH}" cat > ${CLUSTER_CONFIG_PATH} </dev/stderr </dev/stderr </var/lib/mysql/grastate.dat < "${BOOTSTRAP_FILE}" << EOF DELETE FROM mysql.user ; CREATE OR REPLACE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ; GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ; DROP DATABASE IF EXISTS test ; FLUSH PRIVILEGES ; EOF CLUSTER_INIT_ARGS="${CLUSTER_INIT_ARGS} --init-file=${BOOTSTRAP_FILE}" fi exec mysqld ${CLUSTER_INIT_ARGS}