github.com/percona/percona-xtradb-cluster-operator@v1.14.0/build/get-pxc-state (about) 1 #!/bin/bash 2 3 function mysql_root_exec() { 4 local server="$1" 5 local query="$2" 6 7 { set +x; } 2>/dev/null 8 mysql_pass=$(cat /etc/mysql/mysql-users-secret/monitor || :) 9 MYSQL_PASSWORD="${mysql_pass:-$MONITOR_PASSWORD}" 10 MYSQL_USERNAME="${MYSQL_USERNAME:-monitor}" 11 MYSQL_PWD=${MYSQL_PASSWORD:-password} timeout 600 mysql -P33062 -h${server} -u${MYSQL_USERNAME} -s -NB -e "${query}" 12 set -x 13 } 14 15 function wait_for_mysql() { 16 local h="$1" 17 for i in {1..10}; do 18 if [ "$(mysql_root_exec "$h" 'select 1')" == "1" ]; then 19 return 20 fi 21 echo "MySQL is not up yet... sleeping ..." 22 sleep 1 23 done 24 } 25 26 echo 27 while read -ra LINE; do 28 wait_for_mysql $LINE 29 STATUS=$(mysql_root_exec "$LINE" "SHOW GLOBAL STATUS LIKE 'wsrep_%';") 30 READY=$(echo "$STATUS" | grep wsrep_ready | awk '{print$2}') 31 ONLINE=$(echo "$STATUS" | grep wsrep_connected | awk '{print$2}') 32 STATE=$(echo "$STATUS" | grep wsrep_local_state_comment | awk '{print$2}') 33 CLUSTER_STATUS=$(echo "$STATUS" | grep wsrep_cluster_status | awk '{print$2}') 34 35 echo node:$LINE:wsrep_ready:$READY:wsrep_connected:$ONLINE:wsrep_local_state_comment:$STATE:wsrep_cluster_status:$CLUSTER_STATUS 36 done