From 3360370fd7ed48d6c65d05c8e242c3dd224dee46 Mon Sep 17 00:00:00 2001 From: ckonstanski Date: Fri, 29 Sep 2017 19:54:04 -0600 Subject: clustercheck.sh typo in name --- salt/openbook/database/files/clustercheck.sh | 85 ++++++++++++++++++++++++++++ salt/openbook/database/files/clusterckeck.sh | 85 ---------------------------- 2 files changed, 85 insertions(+), 85 deletions(-) create mode 100644 salt/openbook/database/files/clustercheck.sh delete mode 100644 salt/openbook/database/files/clusterckeck.sh diff --git a/salt/openbook/database/files/clustercheck.sh b/salt/openbook/database/files/clustercheck.sh new file mode 100644 index 0000000..adb5da8 --- /dev/null +++ b/salt/openbook/database/files/clustercheck.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# +# Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly +# +# Author: Olaf van Zandwijk +# Author: Raghavendra Prabhu +# +# Documentation and download: https://github.com/olafz/percona-clustercheck +# +# Based on the original script from Unai Rodriguez +# +# This implementation depends on the presence of a ~/.my.cnf file for the mysql username and password. + +if [[ $1 == '-h' || $1 == '--help' ]]; then + echo "Usage: $0 " + exit 1 +fi + +# if the disabled file is present, return 503. This allows +# admins to manually remove a node from a cluster easily. +if [ -e "/var/tmp/clustercheck.disabled" ]; then + 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: 51\r\n" + echo -en "\r\n" + echo -en "Percona XtraDB Cluster Node is manually disabled.\r\n" + sleep 0.1 + exit 1 +fi + +AVAILABLE_WHEN_DONOR=${1:-1} +AVAILABLE_WHEN_READONLY=${2:-1} +ERR_FILE="${3:-/dev/null}" +DEFAULTS_EXTRA_FILE="${4:-/etc/my.cnf}" + +#Timeout exists for instances where mysqld may be hung +TIMEOUT=10 + +EXTRA_ARGS="" +if [[ -r $DEFAULTS_EXTRA_FILE ]]; then + MYSQL_CMDLINE="mysql --defaults-extra-file=$DEFAULTS_EXTRA_FILE --connect-timeout=$TIMEOUT ${EXTRA_ARGS}" +else + MYSQL_CMDLINE="mysql --connect-timeout=$TIMEOUT ${EXTRA_ARGS}" +fi + +# Perform the query to check the wsrep_local_state +WSREP_STATUS=$($MYSQL_CMDLINE -e "SHOW STATUS LIKE 'wsrep_local_state';" 2>${ERR_FILE} | tail -1 | awk '{print $2;}' 2>>${ERR_FILE}) +if [[ "${WSREP_STATUS}" == "4" ]] || [[ "${WSREP_STATUS}" == "2" && ${AVAILABLE_WHEN_DONOR} == 1 ]]; then + # Check only when set to 0 to avoid latency in response. + if [[ $AVAILABLE_WHEN_READONLY -eq 0 ]]; then + READ_ONLY=$($MYSQL_CMDLINE -e "SHOW GLOBAL VARIABLES LIKE 'read_only';" 2>${ERR_FILE} | tail -1 | awk '{print $2;}' 2>>${ERR_FILE}) + if [[ "${READ_ONLY}" == "ON" ]]; then + # Percona XtraDB Cluster node local state is 'Synced', but it is in + # read-only mode. The variable AVAILABLE_WHEN_READONLY is set to 0. + 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: 43\r\n" + echo -en "\r\n" + echo -en "Percona XtraDB Cluster Node is read-only.\r\n" + sleep 0.1 + exit 1 + fi + fi + # Percona XtraDB Cluster node local state is 'Synced' + echo -en "HTTP/1.1 200 OK\r\n" + echo -en "Content-Type: text/plain\r\n" + echo -en "Connection: close\r\n" + echo -en "Content-Length: 40\r\n" + echo -en "\r\n" + echo -en "Percona XtraDB Cluster Node is synced.\r\n" + sleep 0.1 + exit 0 +else + # Percona XtraDB Cluster node local state is not 'Synced' + 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 Node is not synced.\r\n" + sleep 0.1 + exit 1 +fi diff --git a/salt/openbook/database/files/clusterckeck.sh b/salt/openbook/database/files/clusterckeck.sh deleted file mode 100644 index adb5da8..0000000 --- a/salt/openbook/database/files/clusterckeck.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash -# -# Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly -# -# Author: Olaf van Zandwijk -# Author: Raghavendra Prabhu -# -# Documentation and download: https://github.com/olafz/percona-clustercheck -# -# Based on the original script from Unai Rodriguez -# -# This implementation depends on the presence of a ~/.my.cnf file for the mysql username and password. - -if [[ $1 == '-h' || $1 == '--help' ]]; then - echo "Usage: $0 " - exit 1 -fi - -# if the disabled file is present, return 503. This allows -# admins to manually remove a node from a cluster easily. -if [ -e "/var/tmp/clustercheck.disabled" ]; then - 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: 51\r\n" - echo -en "\r\n" - echo -en "Percona XtraDB Cluster Node is manually disabled.\r\n" - sleep 0.1 - exit 1 -fi - -AVAILABLE_WHEN_DONOR=${1:-1} -AVAILABLE_WHEN_READONLY=${2:-1} -ERR_FILE="${3:-/dev/null}" -DEFAULTS_EXTRA_FILE="${4:-/etc/my.cnf}" - -#Timeout exists for instances where mysqld may be hung -TIMEOUT=10 - -EXTRA_ARGS="" -if [[ -r $DEFAULTS_EXTRA_FILE ]]; then - MYSQL_CMDLINE="mysql --defaults-extra-file=$DEFAULTS_EXTRA_FILE --connect-timeout=$TIMEOUT ${EXTRA_ARGS}" -else - MYSQL_CMDLINE="mysql --connect-timeout=$TIMEOUT ${EXTRA_ARGS}" -fi - -# Perform the query to check the wsrep_local_state -WSREP_STATUS=$($MYSQL_CMDLINE -e "SHOW STATUS LIKE 'wsrep_local_state';" 2>${ERR_FILE} | tail -1 | awk '{print $2;}' 2>>${ERR_FILE}) -if [[ "${WSREP_STATUS}" == "4" ]] || [[ "${WSREP_STATUS}" == "2" && ${AVAILABLE_WHEN_DONOR} == 1 ]]; then - # Check only when set to 0 to avoid latency in response. - if [[ $AVAILABLE_WHEN_READONLY -eq 0 ]]; then - READ_ONLY=$($MYSQL_CMDLINE -e "SHOW GLOBAL VARIABLES LIKE 'read_only';" 2>${ERR_FILE} | tail -1 | awk '{print $2;}' 2>>${ERR_FILE}) - if [[ "${READ_ONLY}" == "ON" ]]; then - # Percona XtraDB Cluster node local state is 'Synced', but it is in - # read-only mode. The variable AVAILABLE_WHEN_READONLY is set to 0. - 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: 43\r\n" - echo -en "\r\n" - echo -en "Percona XtraDB Cluster Node is read-only.\r\n" - sleep 0.1 - exit 1 - fi - fi - # Percona XtraDB Cluster node local state is 'Synced' - echo -en "HTTP/1.1 200 OK\r\n" - echo -en "Content-Type: text/plain\r\n" - echo -en "Connection: close\r\n" - echo -en "Content-Length: 40\r\n" - echo -en "\r\n" - echo -en "Percona XtraDB Cluster Node is synced.\r\n" - sleep 0.1 - exit 0 -else - # Percona XtraDB Cluster node local state is not 'Synced' - 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 Node is not synced.\r\n" - sleep 0.1 - exit 1 -fi -- cgit v1.3