summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Konstanski <ckonstanski@pippiandcarlos.com>2017-09-29 16:53:20 -0600
committerCarlos Konstanski <ckonstanski@pippiandcarlos.com>2017-09-29 16:53:20 -0600
commit390980eb6a94b9a7b060e5717f10f041fe7ca234 (patch)
tree138a3c24491f28e98797ca759f37127d3ca1c8c1
parentca5e30661204a2da2c6fc017ea2359df4b15af4b (diff)
clustercheck
-rw-r--r--pillar/openbook/database.sls20
-rw-r--r--salt/openbook/database/files/build.sh1
-rw-r--r--salt/openbook/database/files/clustercheck14
-rw-r--r--salt/openbook/database/files/clusterckeck.sh85
-rw-r--r--salt/openbook/database/files/installdeps.sh3
-rw-r--r--salt/openbook/database/files/start_galera_node.sh1
6 files changed, 122 insertions, 2 deletions
diff --git a/pillar/openbook/database.sls b/pillar/openbook/database.sls
index e495cf2..a9c09c3 100644
--- a/pillar/openbook/database.sls
+++ b/pillar/openbook/database.sls
@@ -24,6 +24,10 @@ database:
name: /etc/openbook/database/bin
mode: "0755"
relative_to_buildroot: False
+ etc_xinetd_d:
+ name: /etc/xinetd.d
+ mode: "0755"
+ relative_to_buildroot: False
data_root:
name: data/root
mode: "0700"
@@ -133,3 +137,19 @@ database:
is_template: True
relative_to_buildroot: False
ansible: True
+ clustercheck_sh:
+ name: clustercheck.sh
+ path: /etc/openbook/database/bin
+ source: clustercheck.sh
+ mode: "0755"
+ is_template: False
+ relative_to_buildroot: False
+ ansible: True
+ clustercheck:
+ name: clustercheck
+ path: /etc/xinetd.d
+ source: clustercheck
+ mode: "0644"
+ is_template: False
+ relative_to_buildroot: False
+ ansible: True
diff --git a/salt/openbook/database/files/build.sh b/salt/openbook/database/files/build.sh
index 49c9aba..b09fc94 100644
--- a/salt/openbook/database/files/build.sh
+++ b/salt/openbook/database/files/build.sh
@@ -1,4 +1,3 @@
--
#!/bin/bash
# Do not call directly. Meant to be called from CI build script.
diff --git a/salt/openbook/database/files/clustercheck b/salt/openbook/database/files/clustercheck
new file mode 100644
index 0000000..00db2ad
--- /dev/null
+++ b/salt/openbook/database/files/clustercheck
@@ -0,0 +1,14 @@
+service clustercheck
+{
+ disable = no
+ flags = REUSE
+ socket_type = stream
+ type = UNLISTED
+ port = 9200
+ wait = no
+ user = nobody
+ server = /etc/openbook/database/bin/clustercheck.sh
+ log_on_failure += USERID
+ only_from = 0.0.0.0/0
+ per_source = UNLIMITED
+}
diff --git a/salt/openbook/database/files/clusterckeck.sh b/salt/openbook/database/files/clusterckeck.sh
new file mode 100644
index 0000000..adb5da8
--- /dev/null
+++ b/salt/openbook/database/files/clusterckeck.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 <olaf.vanzandwijk@nedap.com>
+# Author: Raghavendra Prabhu <raghavendra.prabhu@percona.com>
+#
+# 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 <available_when_donor=0|1> <available_when_readonly=0|1> <log_file> <defaults_extra_file>"
+ 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/installdeps.sh b/salt/openbook/database/files/installdeps.sh
index cd068fa..d04a4db 100644
--- a/salt/openbook/database/files/installdeps.sh
+++ b/salt/openbook/database/files/installdeps.sh
@@ -6,7 +6,8 @@ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74C
add-apt-repository 'deb [arch=amd64,i386] http://sgp1.mirrors.digitalocean.com/mariadb/repo/10.1/ubuntu xenial main'
apt-get update
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
-apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install netcat mariadb-server-10.1
+apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install netcat mariadb-server-10.1 xinetd
service mysql stop
+service xinetd stop
exit 0
diff --git a/salt/openbook/database/files/start_galera_node.sh b/salt/openbook/database/files/start_galera_node.sh
index 29b7e55..3746a0d 100644
--- a/salt/openbook/database/files/start_galera_node.sh
+++ b/salt/openbook/database/files/start_galera_node.sh
@@ -9,4 +9,5 @@ if [ ! -d "{{ pillar["database"]["dirs"]["var_lib_mysql"]["name"] }}/mysql" ]; t
fi
/etc/mysql/bin/fix_permissions.sh &
+/etc/init.d/xinetd start
exec /usr/sbin/mysqld ${@}