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
1=== added file 'scripts/clustercheck.sh'
2--- scripts/clustercheck.sh 1970-01-01 00:00:00 +0000
3+++ scripts/clustercheck.sh 2015-01-04 18:21:35 +0000
4@@ -0,0 +1,94 @@
5+#!/bin/bash
6+#
7+# Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly
8+#
9+# Authors:
10+# Raghavendra Prabhu <raghavendra.prabhu@percona.com>
11+# Olaf van Zandwijk <olaf.vanzandwijk@nedap.com>
12+#
13+# Based on the original script from Unai Rodriguez and Olaf (https://github.com/olafz/percona-clustercheck)
14+#
15+# Grant privileges required:
16+# GRANT PROCESS ON *.* TO 'clustercheckuser'@'localhost' IDENTIFIED BY 'clustercheckpassword!';
17+
18+if [[ $1 == '-h' || $1 == '--help' ]];then
19+ echo "Usage: $0 <user> <pass> <available_when_donor=0|1> <log_file> <available_when_readonly=0|1> <defaults_extra_file>"
20+ exit
21+fi
22+
23+MYSQL_USERNAME="${1-clustercheckuser}"
24+MYSQL_PASSWORD="${2-clustercheckpassword!}"
25+AVAILABLE_WHEN_DONOR=${3:-0}
26+ERR_FILE="${4:-/dev/null}"
27+AVAILABLE_WHEN_READONLY=${5:-1}
28+DEFAULTS_EXTRA_FILE=${6:-/etc/my.cnf}
29+#Timeout exists for instances where mysqld may be hung
30+TIMEOUT=10
31+
32+EXTRA_ARGS=""
33+if [[ -n "$MYSQL_USERNAME" ]]; then
34+ EXTRA_ARGS="$EXTRA_ARGS --user=${MYSQL_USERNAME}"
35+fi
36+if [[ -n "$MYSQL_PASSWORD" ]]; then
37+ EXTRA_ARGS="$EXTRA_ARGS --password=${MYSQL_PASSWORD}"
38+fi
39+if [[ -r $DEFAULTS_EXTRA_FILE ]];then
40+ MYSQL_CMDLINE="mysql --defaults-extra-file=$DEFAULTS_EXTRA_FILE -nNE --connect-timeout=$TIMEOUT \
41+ ${EXTRA_ARGS}"
42+else
43+ MYSQL_CMDLINE="mysql -nNE --connect-timeout=$TIMEOUT ${EXTRA_ARGS}"
44+fi
45+#
46+# Perform the query to check the wsrep_local_state
47+#
48+WSREP_STATUS=($($MYSQL_CMDLINE -e "SHOW GLOBAL STATUS LIKE 'wsrep_%';" \
49+ 2>${ERR_FILE} | grep -A 1 -E 'wsrep_local_state$|wsrep_cluster_status$' \
50+ | sed -n -e '2p' -e '5p' | tr '\n' ' '))
51+
52+if [[ ${WSREP_STATUS[1]} == 'Primary' && ( ${WSREP_STATUS[0]} -eq 4 || \
53+ ( ${WSREP_STATUS[0]} -eq 2 && $AVAILABLE_WHEN_DONOR -eq 1 ) ) ]]
54+then
55+
56+ # Check only when set to 0 to avoid latency in response.
57+ if [[ $AVAILABLE_WHEN_READONLY -eq 0 ]];then
58+ READ_ONLY=$($MYSQL_CMDLINE -e "SHOW GLOBAL VARIABLES LIKE 'read_only';" \
59+ 2>${ERR_FILE} | tail -1 2>>${ERR_FILE})
60+
61+ if [[ "${READ_ONLY}" == "ON" ]];then
62+ # Percona XtraDB Cluster node local state is 'Synced', but it is in
63+ # read-only mode. The variable AVAILABLE_WHEN_READONLY is set to 0.
64+ # => return HTTP 503
65+ # Shell return-code is 1
66+ echo -en "HTTP/1.1 503 Service Unavailable\r\n"
67+ echo -en "Content-Type: text/plain\r\n"
68+ echo -en "Connection: close\r\n"
69+ echo -en "Content-Length: 43\r\n"
70+ echo -en "\r\n"
71+ echo -en "Percona XtraDB Cluster Node is read-only.\r\n"
72+ sleep 0.1
73+ exit 1
74+ fi
75+
76+ fi
77+ # Percona XtraDB Cluster node local state is 'Synced' => return HTTP 200
78+ # Shell return-code is 0
79+ echo -en "HTTP/1.1 200 OK\r\n"
80+ echo -en "Content-Type: text/plain\r\n"
81+ echo -en "Connection: close\r\n"
82+ echo -en "Content-Length: 40\r\n"
83+ echo -en "\r\n"
84+ echo -en "Percona XtraDB Cluster Node is synced.\r\n"
85+ sleep 0.1
86+ exit 0
87+else
88+ # Percona XtraDB Cluster node local state is not 'Synced' => return HTTP 503
89+ # Shell return-code is 1
90+ echo -en "HTTP/1.1 503 Service Unavailable\r\n"
91+ echo -en "Content-Type: text/plain\r\n"
92+ echo -en "Connection: close\r\n"
93+ echo -en "Content-Length: 57\r\n"
94+ echo -en "\r\n"
95+ echo -en "Percona XtraDB Cluster Node is not synced or non-PRIM. \r\n"
96+ sleep 0.1
97+ exit 1
98+fi
99
100=== removed file 'scripts/clustercheck.sh'
101--- scripts/clustercheck.sh 2014-08-30 06:05:25 +0000
102+++ scripts/clustercheck.sh 1970-01-01 00:00:00 +0000
103@@ -1,92 +0,0 @@
104-#!/bin/bash
105-#
106-# Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly
107-#
108-# Authors:
109-# Raghavendra Prabhu <raghavendra.prabhu@percona.com>
110-# Olaf van Zandwijk <olaf.vanzandwijk@nedap.com>
111-#
112-# Based on the original script from Unai Rodriguez and Olaf (https://github.com/olafz/percona-clustercheck)
113-#
114-# Grant privileges required:
115-# GRANT PROCESS ON *.* TO 'clustercheckuser'@'localhost' IDENTIFIED BY 'clustercheckpassword!';
116-
117-if [[ $1 == '-h' || $1 == '--help' ]];then
118- echo "Usage: $0 <user> <pass> <available_when_donor=0|1> <log_file> <available_when_readonly=0|1> <defaults_extra_file>"
119- exit
120-fi
121-
122-MYSQL_USERNAME="${1-clustercheckuser}"
123-MYSQL_PASSWORD="${2-clustercheckpassword!}"
124-AVAILABLE_WHEN_DONOR=${3:-0}
125-ERR_FILE="${4:-/dev/null}"
126-AVAILABLE_WHEN_READONLY=${5:-1}
127-DEFAULTS_EXTRA_FILE=${6:-/etc/my.cnf}
128-#Timeout exists for instances where mysqld may be hung
129-TIMEOUT=10
130-
131-EXTRA_ARGS=""
132-if [[ -n "$MYSQL_USERNAME" ]]; then
133- EXTRA_ARGS="$EXTRA_ARGS --user=${MYSQL_USERNAME}"
134-fi
135-if [[ -n "$MYSQL_PASSWORD" ]]; then
136- EXTRA_ARGS="$EXTRA_ARGS --password=${MYSQL_PASSWORD}"
137-fi
138-if [[ -r $DEFAULTS_EXTRA_FILE ]];then
139- MYSQL_CMDLINE="mysql --defaults-extra-file=$DEFAULTS_EXTRA_FILE -nNE --connect-timeout=$TIMEOUT \
140- ${EXTRA_ARGS}"
141-else
142- MYSQL_CMDLINE="mysql -nNE --connect-timeout=$TIMEOUT ${EXTRA_ARGS}"
143-fi
144-#
145-# Perform the query to check the wsrep_local_state
146-#
147-WSREP_STATUS=$($MYSQL_CMDLINE -e "SHOW STATUS LIKE 'wsrep_local_state';" \
148- 2>${ERR_FILE} | tail -1 2>>${ERR_FILE})
149-
150-if [[ "${WSREP_STATUS}" == "4" ]] || [[ "${WSREP_STATUS}" == "2" && ${AVAILABLE_WHEN_DONOR} == 1 ]]
151-then
152-
153- # Check only when set to 0 to avoid latency in response.
154- if [[ $AVAILABLE_WHEN_READONLY -eq 0 ]];then
155- READ_ONLY=$($MYSQL_CMDLINE -e "SHOW GLOBAL VARIABLES LIKE 'read_only';" \
156- 2>${ERR_FILE} | tail -1 2>>${ERR_FILE})
157-
158- if [[ "${READ_ONLY}" == "ON" ]];then
159- # Percona XtraDB Cluster node local state is 'Synced', but it is in
160- # read-only mode. The variable AVAILABLE_WHEN_READONLY is set to 0.
161- # => return HTTP 503
162- # Shell return-code is 1
163- echo -en "HTTP/1.1 503 Service Unavailable\r\n"
164- echo -en "Content-Type: text/plain\r\n"
165- echo -en "Connection: close\r\n"
166- echo -en "Content-Length: 43\r\n"
167- echo -en "\r\n"
168- echo -en "Percona XtraDB Cluster Node is read-only.\r\n"
169- sleep 0.1
170- exit 1
171- fi
172-
173- fi
174- # Percona XtraDB Cluster node local state is 'Synced' => return HTTP 200
175- # Shell return-code is 0
176- echo -en "HTTP/1.1 200 OK\r\n"
177- echo -en "Content-Type: text/plain\r\n"
178- echo -en "Connection: close\r\n"
179- echo -en "Content-Length: 40\r\n"
180- echo -en "\r\n"
181- echo -en "Percona XtraDB Cluster Node is synced.\r\n"
182- sleep 0.1
183- exit 0
184-else
185- # Percona XtraDB Cluster node local state is not 'Synced' => return HTTP 503
186- # Shell return-code is 1
187- echo -en "HTTP/1.1 503 Service Unavailable\r\n"
188- echo -en "Content-Type: text/plain\r\n"
189- echo -en "Connection: close\r\n"
190- echo -en "Content-Length: 44\r\n"
191- echo -en "\r\n"
192- echo -en "Percona XtraDB Cluster Node is not synced.\r\n"
193- sleep 0.1
194- exit 1
195-fi

Subscribers

People subscribed via source and target branches

to all changes: