Merge lp:~percona-core/percona-xtradb-cluster/bug-1403566-5.5 into lp:percona-xtradb-cluster/5.5

Proposed by Raghavendra D Prabhu
Status: Merged
Approved by: Alexey Kopytov
Approved revision: 838
Merge reported by: Raghavendra D Prabhu
Merged at revision: not available
Proposed branch: lp:~percona-core/percona-xtradb-cluster/bug-1403566-5.5
Merge into: lp:percona-xtradb-cluster/5.5
Diff against target: 195 lines (+0/-92)
1 file modified
scripts/clustercheck.sh (+0/-92)
To merge this branch: bzr merge lp:~percona-core/percona-xtradb-cluster/bug-1403566-5.5
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+245522@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'scripts/clustercheck.sh'
--- scripts/clustercheck.sh 1970-01-01 00:00:00 +0000
+++ scripts/clustercheck.sh 2015-01-04 18:21:35 +0000
@@ -0,0 +1,94 @@
1#!/bin/bash
2#
3# Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly
4#
5# Authors:
6# Raghavendra Prabhu <raghavendra.prabhu@percona.com>
7# Olaf van Zandwijk <olaf.vanzandwijk@nedap.com>
8#
9# Based on the original script from Unai Rodriguez and Olaf (https://github.com/olafz/percona-clustercheck)
10#
11# Grant privileges required:
12# GRANT PROCESS ON *.* TO 'clustercheckuser'@'localhost' IDENTIFIED BY 'clustercheckpassword!';
13
14if [[ $1 == '-h' || $1 == '--help' ]];then
15 echo "Usage: $0 <user> <pass> <available_when_donor=0|1> <log_file> <available_when_readonly=0|1> <defaults_extra_file>"
16 exit
17fi
18
19MYSQL_USERNAME="${1-clustercheckuser}"
20MYSQL_PASSWORD="${2-clustercheckpassword!}"
21AVAILABLE_WHEN_DONOR=${3:-0}
22ERR_FILE="${4:-/dev/null}"
23AVAILABLE_WHEN_READONLY=${5:-1}
24DEFAULTS_EXTRA_FILE=${6:-/etc/my.cnf}
25#Timeout exists for instances where mysqld may be hung
26TIMEOUT=10
27
28EXTRA_ARGS=""
29if [[ -n "$MYSQL_USERNAME" ]]; then
30 EXTRA_ARGS="$EXTRA_ARGS --user=${MYSQL_USERNAME}"
31fi
32if [[ -n "$MYSQL_PASSWORD" ]]; then
33 EXTRA_ARGS="$EXTRA_ARGS --password=${MYSQL_PASSWORD}"
34fi
35if [[ -r $DEFAULTS_EXTRA_FILE ]];then
36 MYSQL_CMDLINE="mysql --defaults-extra-file=$DEFAULTS_EXTRA_FILE -nNE --connect-timeout=$TIMEOUT \
37 ${EXTRA_ARGS}"
38else
39 MYSQL_CMDLINE="mysql -nNE --connect-timeout=$TIMEOUT ${EXTRA_ARGS}"
40fi
41#
42# Perform the query to check the wsrep_local_state
43#
44WSREP_STATUS=($($MYSQL_CMDLINE -e "SHOW GLOBAL STATUS LIKE 'wsrep_%';" \
45 2>${ERR_FILE} | grep -A 1 -E 'wsrep_local_state$|wsrep_cluster_status$' \
46 | sed -n -e '2p' -e '5p' | tr '\n' ' '))
47
48if [[ ${WSREP_STATUS[1]} == 'Primary' && ( ${WSREP_STATUS[0]} -eq 4 || \
49 ( ${WSREP_STATUS[0]} -eq 2 && $AVAILABLE_WHEN_DONOR -eq 1 ) ) ]]
50then
51
52 # Check only when set to 0 to avoid latency in response.
53 if [[ $AVAILABLE_WHEN_READONLY -eq 0 ]];then
54 READ_ONLY=$($MYSQL_CMDLINE -e "SHOW GLOBAL VARIABLES LIKE 'read_only';" \
55 2>${ERR_FILE} | tail -1 2>>${ERR_FILE})
56
57 if [[ "${READ_ONLY}" == "ON" ]];then
58 # Percona XtraDB Cluster node local state is 'Synced', but it is in
59 # read-only mode. The variable AVAILABLE_WHEN_READONLY is set to 0.
60 # => return HTTP 503
61 # Shell return-code is 1
62 echo -en "HTTP/1.1 503 Service Unavailable\r\n"
63 echo -en "Content-Type: text/plain\r\n"
64 echo -en "Connection: close\r\n"
65 echo -en "Content-Length: 43\r\n"
66 echo -en "\r\n"
67 echo -en "Percona XtraDB Cluster Node is read-only.\r\n"
68 sleep 0.1
69 exit 1
70 fi
71
72 fi
73 # Percona XtraDB Cluster node local state is 'Synced' => return HTTP 200
74 # Shell return-code is 0
75 echo -en "HTTP/1.1 200 OK\r\n"
76 echo -en "Content-Type: text/plain\r\n"
77 echo -en "Connection: close\r\n"
78 echo -en "Content-Length: 40\r\n"
79 echo -en "\r\n"
80 echo -en "Percona XtraDB Cluster Node is synced.\r\n"
81 sleep 0.1
82 exit 0
83else
84 # Percona XtraDB Cluster node local state is not 'Synced' => return HTTP 503
85 # Shell return-code is 1
86 echo -en "HTTP/1.1 503 Service Unavailable\r\n"
87 echo -en "Content-Type: text/plain\r\n"
88 echo -en "Connection: close\r\n"
89 echo -en "Content-Length: 57\r\n"
90 echo -en "\r\n"
91 echo -en "Percona XtraDB Cluster Node is not synced or non-PRIM. \r\n"
92 sleep 0.1
93 exit 1
94fi
095
=== removed file 'scripts/clustercheck.sh'
--- scripts/clustercheck.sh 2014-08-30 06:05:25 +0000
+++ scripts/clustercheck.sh 1970-01-01 00:00:00 +0000
@@ -1,92 +0,0 @@
1#!/bin/bash
2#
3# Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly
4#
5# Authors:
6# Raghavendra Prabhu <raghavendra.prabhu@percona.com>
7# Olaf van Zandwijk <olaf.vanzandwijk@nedap.com>
8#
9# Based on the original script from Unai Rodriguez and Olaf (https://github.com/olafz/percona-clustercheck)
10#
11# Grant privileges required:
12# GRANT PROCESS ON *.* TO 'clustercheckuser'@'localhost' IDENTIFIED BY 'clustercheckpassword!';
13
14if [[ $1 == '-h' || $1 == '--help' ]];then
15 echo "Usage: $0 <user> <pass> <available_when_donor=0|1> <log_file> <available_when_readonly=0|1> <defaults_extra_file>"
16 exit
17fi
18
19MYSQL_USERNAME="${1-clustercheckuser}"
20MYSQL_PASSWORD="${2-clustercheckpassword!}"
21AVAILABLE_WHEN_DONOR=${3:-0}
22ERR_FILE="${4:-/dev/null}"
23AVAILABLE_WHEN_READONLY=${5:-1}
24DEFAULTS_EXTRA_FILE=${6:-/etc/my.cnf}
25#Timeout exists for instances where mysqld may be hung
26TIMEOUT=10
27
28EXTRA_ARGS=""
29if [[ -n "$MYSQL_USERNAME" ]]; then
30 EXTRA_ARGS="$EXTRA_ARGS --user=${MYSQL_USERNAME}"
31fi
32if [[ -n "$MYSQL_PASSWORD" ]]; then
33 EXTRA_ARGS="$EXTRA_ARGS --password=${MYSQL_PASSWORD}"
34fi
35if [[ -r $DEFAULTS_EXTRA_FILE ]];then
36 MYSQL_CMDLINE="mysql --defaults-extra-file=$DEFAULTS_EXTRA_FILE -nNE --connect-timeout=$TIMEOUT \
37 ${EXTRA_ARGS}"
38else
39 MYSQL_CMDLINE="mysql -nNE --connect-timeout=$TIMEOUT ${EXTRA_ARGS}"
40fi
41#
42# Perform the query to check the wsrep_local_state
43#
44WSREP_STATUS=$($MYSQL_CMDLINE -e "SHOW STATUS LIKE 'wsrep_local_state';" \
45 2>${ERR_FILE} | tail -1 2>>${ERR_FILE})
46
47if [[ "${WSREP_STATUS}" == "4" ]] || [[ "${WSREP_STATUS}" == "2" && ${AVAILABLE_WHEN_DONOR} == 1 ]]
48then
49
50 # Check only when set to 0 to avoid latency in response.
51 if [[ $AVAILABLE_WHEN_READONLY -eq 0 ]];then
52 READ_ONLY=$($MYSQL_CMDLINE -e "SHOW GLOBAL VARIABLES LIKE 'read_only';" \
53 2>${ERR_FILE} | tail -1 2>>${ERR_FILE})
54
55 if [[ "${READ_ONLY}" == "ON" ]];then
56 # Percona XtraDB Cluster node local state is 'Synced', but it is in
57 # read-only mode. The variable AVAILABLE_WHEN_READONLY is set to 0.
58 # => return HTTP 503
59 # Shell return-code is 1
60 echo -en "HTTP/1.1 503 Service Unavailable\r\n"
61 echo -en "Content-Type: text/plain\r\n"
62 echo -en "Connection: close\r\n"
63 echo -en "Content-Length: 43\r\n"
64 echo -en "\r\n"
65 echo -en "Percona XtraDB Cluster Node is read-only.\r\n"
66 sleep 0.1
67 exit 1
68 fi
69
70 fi
71 # Percona XtraDB Cluster node local state is 'Synced' => return HTTP 200
72 # Shell return-code is 0
73 echo -en "HTTP/1.1 200 OK\r\n"
74 echo -en "Content-Type: text/plain\r\n"
75 echo -en "Connection: close\r\n"
76 echo -en "Content-Length: 40\r\n"
77 echo -en "\r\n"
78 echo -en "Percona XtraDB Cluster Node is synced.\r\n"
79 sleep 0.1
80 exit 0
81else
82 # Percona XtraDB Cluster node local state is not 'Synced' => return HTTP 503
83 # Shell return-code is 1
84 echo -en "HTTP/1.1 503 Service Unavailable\r\n"
85 echo -en "Content-Type: text/plain\r\n"
86 echo -en "Connection: close\r\n"
87 echo -en "Content-Length: 44\r\n"
88 echo -en "\r\n"
89 echo -en "Percona XtraDB Cluster Node is not synced.\r\n"
90 sleep 0.1
91 exit 1
92fi

Subscribers

People subscribed via source and target branches

to all changes: