
Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/934430 Change-Id: Id20fa5e0b5dc0b2c1e5330799e0edbc20bbd2605
73 lines
2.2 KiB
Django/Jinja
73 lines
2.2 KiB
Django/Jinja
#!/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 ! {{ galera_mariadb_client_binary }} --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 {{ galera_mariadb_service_name }}> /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 {{ galera_mariadb_service_name }}; then
|
|
EXIT_CODE=3
|
|
else
|
|
echo "Cluster bootstrap failed."
|
|
systemctl status {{ galera_mariadb_service_name }}
|
|
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}
|