-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclustercheck
116 lines (102 loc) · 3.49 KB
/
clustercheck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# Script to make a proxy (e.g., HAProxy) capable of monitoring MariaDB Cluster nodes properly
#
# Usage: ./script.sh <user> <password> [<defaults_extra_file>]
#
if [[ $1 == '-h' || $1 == '--help' ]]; then
echo "Usage: $0 <user> <pass> [<defaults_extra_file>]"
exit 0
fi
# Arguments
MYSQL_USERNAME="$1"
MYSQL_PASSWORD="$2"
DEFAULTS_EXTRA_FILE="${3:-/etc/my.cnf}"
# Timeout for MySQL connection
TIMEOUT=10
# Disabled check
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: 45\r\n"
echo -en "\r\n"
echo -en "MariaDB Cluster Node is manually disabled.\r\n"
exit 1
fi
# MySQL command
if [[ -r $DEFAULTS_EXTRA_FILE ]]; then
MYSQL_CMD="mariadb --defaults-extra-file=$DEFAULTS_EXTRA_FILE -nNE --connect-timeout=$TIMEOUT --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD}"
else
MYSQL_CMD="mariadb -nNE --connect-timeout=$TIMEOUT --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD}"
fi
# Check wsrep_local_state_comment
WSREP_STATUS=$($MYSQL_CMD -e "SHOW STATUS LIKE 'wsrep_local_state_comment';" 2>/dev/null | awk 'NR==3 {print $1}')
if [[ "$WSREP_STATUS" == "Synced" ]]; then
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: 34\r\n"
echo -en "\r\n"
echo -en "MariaDB Cluster Node is synced.\r\n"
exit 0
else
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: 38\r\n"
echo -en "\r\n"
echo -en "MariaDB Cluster Node is not synced.\r\n"
exit 1
fi
1~#!/bin/bash
#
# Script to make a proxy (e.g., HAProxy) capable of monitoring MariaDB Cluster nodes properly
#
# Usage: ./script.sh <user> <password> [<defaults_extra_file>]
#
if [[ $1 == '-h' || $1 == '--help' ]]; then
echo "Usage: $0 <user> <pass> [<defaults_extra_file>]"
exit 0
fi
# Arguments
MYSQL_USERNAME="$1"
MYSQL_PASSWORD="$2"
DEFAULTS_EXTRA_FILE="${3:-/etc/my.cnf}"
# Timeout for MySQL connection
TIMEOUT=10
# Disabled check
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: 45\r\n"
echo -en "\r\n"
echo -en "MariaDB Cluster Node is manually disabled.\r\n"
exit 1
fi
# MySQL command
if [[ -r $DEFAULTS_EXTRA_FILE ]]; then
MYSQL_CMD="mariadb --defaults-extra-file=$DEFAULTS_EXTRA_FILE -nNE --connect-timeout=$TIMEOUT --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD}"
else
MYSQL_CMD="mariadb -nNE --connect-timeout=$TIMEOUT --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD}"
fi
# Check wsrep_local_state_comment
WSREP_STATUS=$($MYSQL_CMD -e "SHOW STATUS LIKE 'wsrep_local_state_comment';" 2>/dev/null | awk 'NR==2 {print $2}')
if [[ "$WSREP_STATUS" == "Synced" ]]; then
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: 34\r\n"
echo -en "\r\n"
echo -en "MariaDB Cluster Node is synced.\r\n"
exit 0
else
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: 38\r\n"
echo -en "\r\n"
echo -en "MariaDB Cluster Node is not synced.\r\n"
exit 1
fi