Files
openstack-ansible-galera_se…/files/galera_new_cluster
Kevin Carter ca054bd8f7 Tune-up the galera role for efficiency
The galera server role has quite a bit going on within it and because of
recent improvements in Ansible we can make better use of tasks, blocks,
facts, local facts, and organization. This change tunes the role up
following some of our better/more modern patterns allowing the role to
not only be more efficient but also easier to understand and improves
the roles idempotency.

Change-Id: If189a8192f22aafb168587361ca8e6903c918697
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2017-11-29 01:59:52 +00:00

73 lines
2.1 KiB
Bash

#!/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 <<EOF
[mysqld]
wsrep_new_cluster
EOF
}
## Main ----------------------------------------------------------------------
trap cleanup EXIT INT TERM
EXIT_CODE=0
if ! systemctl status mysql > /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; then
EXIT_CODE=3
else
echo "Cluster bootstrap failed."
systemctl status mysql
exit 99
fi
fi
wait_operational
cat <<EOF
NOTICE: Exit code 0 and 3 are success.
Exit 0 is no change, exit 3 is change.
Current Exit Code "${EXIT_CODE}"
EOF
exit ${EXIT_CODE}