Mohammed Naser 7c7ade4fc9 cleanup: refactor into galera_mariadb_service_name
We had two variable names which were duplicated for the service
name, this converges them all to "mariadb" which uses the actual
systemd unit instead of the init.d compatiblity layer.

Change-Id: I5805fb11a5118c4011701377cd30b2511edca505
2019-07-12 12:42:24 -04:00

73 lines
2.1 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 ! 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 {{ 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}