| | 113 | |
| | 114 | ------------------------------------------ |
| | 115 | == keepalived Backup site check DB Group Replicate == |
| | 116 | |
| | 117 | {{{ |
| | 118 | #!sh |
| | 119 | |
| | 120 | #!/usr/bin/bash |
| | 121 | logfile=/tmp/keepalived.log |
| | 122 | echo "Time: $(date). keepalive log -------" >> $logfile |
| | 123 | |
| | 124 | IP_MASTER="192.168.81.12" |
| | 125 | STR_CHECK="ONLINE" |
| | 126 | |
| | 127 | #/usr/bin/unison > /dev/null 2>&1 |
| | 128 | /bin/ping -c 2 -W 1 192.168.81.12 > /dev/null 2>&1 |
| | 129 | status=$? |
| | 130 | echo 'ping ' $status |
| | 131 | if [ $status -eq 0 ] |
| | 132 | then |
| | 133 | all_result=`/usr/bin/docker exec -i nodedb1 mysql -uroot -pmypass -e 'SELECT * FROM performance_schema.replication_group_members;'` |
| | 134 | online=$(echo $all_result | grep "$IP_MASTER" | awk '{ print $12}' ) |
| | 135 | if [[ "$online" == *"$STR_CHECK"* ]] |
| | 136 | then |
| | 137 | echo "Master node OK" >> $logfile |
| | 138 | exit 1 # All good. DB master reachable |
| | 139 | else |
| | 140 | echo "Master node Fail" >> $logfile |
| | 141 | exit 0 # Failover trigger |
| | 142 | fi |
| | 143 | else |
| | 144 | echo "Master node Fail" >> $logfile |
| | 145 | exit 0 # Failover trigger |
| | 146 | fi |
| | 147 | }}} |