forked from severalnines/galera-docker-mariadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_status.sh
executable file
·62 lines (52 loc) · 1.51 KB
/
report_status.sh
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
#!/bin/bash
# Report Galera status to etcd periodically.
# report_status.sh [mysql user] [mysql password] [cluster name] [interval] [comma separated etcd hosts]
# Example:
# report_status.sh root myS3cret galera_cluster 15 192.168.55.111:2379,192.168.55.112:2379,192.168.55.113:2379
USER=$1
PASSWORD=$2
CLUSTER_NAME=$3
TTL=$4
ETCD_HOSTS=$5
function check_etcd()
{
etcd_hosts=$(echo $ETCD_HOSTS | tr ',' ' ')
flag=1
# Loop to find a healthy etcd host
for i in $etcd_hosts
do
curl -s http://$i/health > /dev/null || continue
if curl -s http://$i/health | jq -e 'contains({ "health": "true"})' > /dev/null; then
healthy_etcd=$i
flag=0
break
fi
done
# Flag is 0 if there is a healthy etcd host
[ $flag -ne 0 ] && echo "report>> Couldn't reach healthy etcd nodes."
}
function report_status()
{
var=$1
key=$2
if [ ! -z $var ]; then
check_etcd
URL="http://$healthy_etcd/v2/keys/galera/$CLUSTER_NAME"
output=$(mysql --user=$USER --password=$PASSWORD -A -Bse "show status like '$var'" 2> /dev/null)
if [ -z $key ]; then
key=$(echo $output | awk {'print $1'})
fi
value=$(echo $output | awk {'print $2'})
ipaddr=$(hostname -i | awk {'print $1'})
if [ ! -z $value ]; then
curl -s $URL/$ipaddr/$key -X PUT -d "value=$value&ttl=$TTL" > /dev/null
fi
fi
}
while true;
do
report_status wsrep_local_state_comment
report_status wsrep_last_committed seqno
# report every ttl - 2 to ensure value does not expire
sleep $(($TTL - 2))
done