#!/usr/bin/env bash # Copyright 2017, Rackspace US, Inc. # # 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. ## Shell Opts ---------------------------------------------------------------- set -e ## Functions ----------------------------------------------------------------- function cleanup { echo "Running Cleanup." systemctl unset-environment _WSREP_NEW_CLUSTER || systemctl set-environment _WSREP_NEW_CLUSTER='' if [[ -f "/etc/my.cnf.d/99_bootstrap.cnf" ]]; then rm /etc/my.cnf.d/99_bootstrap.cnf fi } function wait_operational { WAITCMD="while ! mysql --silent --skip-column-names -e 'SHOW STATUS LIKE \"wsrep_evs_state\"' | grep -wq \"OPERATIONAL\"; do sleep 5; done" if ! timeout 180 sh -c "${WAITCMD}"; then echo "Cluster failed to return an \"OPERATIONAL\" state" return 1 else echo "Cluster is now OPERATIONAL" return 0 fi } function bootstrap_opts { cat > /etc/my.cnf.d/99_bootstrap.cnf < /dev/null; then systemctl set-environment _WSREP_NEW_CLUSTER='--wsrep-new-cluster' if grep -rniq -e suse -e opensuse /etc/os-release; then bootstrap_opts fi if systemctl start {{ mysql_service_name }}; then EXIT_CODE=3 else echo "Cluster bootstrap failed." systemctl status {{ mysql_service_name }} exit 99 fi fi wait_operational cat <