From a65f682cc59b0adc0481466b158fbf6252d96dd7 Mon Sep 17 00:00:00 2001 From: Sander Backus Date: Wed, 23 Nov 2022 16:02:42 +0100 Subject: [PATCH] check wsrep_cluster_status (for WSREP not prepared for application use) --- clustercheck | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/clustercheck b/clustercheck index 7098a14..4b36b5a 100755 --- a/clustercheck +++ b/clustercheck @@ -63,6 +63,22 @@ fi # WSREP_STATUS=$($MYSQL_CMDLINE -e "SHOW STATUS LIKE 'wsrep_local_state';" \ 2>${ERR_FILE} | tail -1 2>>${ERR_FILE}) +WSREP_CLUSTER_STATUS=$($MYSQL_CMDLINE -e "SHOW STATUS LIKE 'wsrep_cluster_status';" \ + 2>${ERR_FILE} | tail -1 2>>${ERR_FILE}) + +if [[ "${WSREP_CLUSTER_STATUS}" != "Primary" ]] +then + # Percona XtraDB Cluster node local state is not 'Synced' => return HTTP 503 + # Shell return-code is 1 + echo -en "HTTP/1.1 503 Service Unavailable\r\n" + echo -en "Content-Type: text/plain\r\n" + echo -en "Connection: close\r\n" + echo -en "Content-Length: 44\r\n" + echo -en "\r\n" + echo -en "Percona XtraDB Cluster status Non primary.\r\n" + sleep 0.1 + exit 1; +fi if [[ "${WSREP_STATUS}" == "4" ]] || [[ "${WSREP_STATUS}" == "2" && ${AVAILABLE_WHEN_DONOR} == 1 ]] then