From 893ae32d550236d1bc503f27fabe49f1d3bd5712 Mon Sep 17 00:00:00 2001 From: Pete Birley Date: Tue, 24 Apr 2018 08:29:54 -0500 Subject: [PATCH] MariaDB: clean up readyness checks This PS cleans the readyness checks for the mariadb statefulset. Change-Id: I96075b4a21ed42d5eb596330a0a0131e9712a06e --- mariadb/templates/bin/_readiness.sh.tpl | 49 ++++++++++++------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/mariadb/templates/bin/_readiness.sh.tpl b/mariadb/templates/bin/_readiness.sh.tpl index 4bb8f24616..86f513e217 100644 --- a/mariadb/templates/bin/_readiness.sh.tpl +++ b/mariadb/templates/bin/_readiness.sh.tpl @@ -16,40 +16,37 @@ See the License for the specific language governing permissions and limitations under the License. */}} -set -o pipefail +set -e -MYSQL="mysql --defaults-file=/etc/mysql/admin_user.cnf --host=localhost" +MYSQL="mysql \ + --defaults-file=/etc/mysql/admin_user.cnf \ + --host=localhost \ + --connect-timeout 2" -if [ ! $($MYSQL -e 'select 1') ]; then - echo "Could not SELECT 1" 1>&2 +mysql_status_query () { + STATUS=$1 + $MYSQL -e "show status like \"${STATUS}\"" | \ + awk "/${STATUS}/ { print \$NF; exit }" +} + +if ! $MYSQL -e 'select 1' > /dev/null 2>&1 ; then exit 1 fi -# Set this late, so that we can give a nicer error message above. -set -o errexit - -CLUSTER_STATUS=$($MYSQL -e "show status like 'wsrep_cluster_status'" | tail -n 1 | cut -f 2) -if [ "x${CLUSTER_STATUS}" != "xPrimary" ]; then - echo "Not in primary cluster: '${CLUSTER_STATUS}'" 1>&2 +if [ "x$(mysql_status_query wsrep_cluster_status)" != "xPrimary" ]; then + # Not in primary cluster + exit 1 +fi +if [ "x$(mysql_status_query wsrep_ready)" != "xON" ]; then + # WSREP not ready + exit 1 +fi +if [ "x$(mysql_status_query wsrep_local_state_comment)" != "xSynced" ]; then + # WSREP not synced exit 1 fi -WSREP_READY=$($MYSQL -e "show status like 'wsrep_ready'" | tail -n 1 | cut -f 2) -if [ "x${WSREP_READY}" != "xON" ]; then - echo "WSREP not ready: '${WSREP_READY}'" 1>&2 - exit 1 -fi - -WSREP_STATE=$($MYSQL -e "show status like 'wsrep_local_state_comment'" | tail -n 1 | cut -f 2) -if [ "x${WSREP_STATE}" != "xSynced" ]; then - echo "WSREP not synced: '${WSREP_STATE}'" 1>&2 - exit 1 -fi - -echo "${POD_NAME} ready." 1>&2 - +# If we made it this far, its safe to remove the bootstrap file if present if [ -e ${BOOTSTRAP_FILE} ]; then rm -f ${BOOTSTRAP_FILE} fi - -exit 0