Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Orchestrator STONITH via ProxySQL
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
export ORCHESTRATOR_API='http://10.1.2.113:3000/api http://10.1.2.88:3000/api http://10.1.2.79:3000/api'
OC=/bin/orchestrator-client
PSQL='mysql -uadmin -padmin -P6032 -h127.1'
VER=$(date +%s)
$OC -c raft-leader > /dev/null 2>&1
HASQUORUM=$?
if [ "x${HASQUORUM}" != "x0" ]; then
echo "Orchestrator quorum is lost!"
echo "Setting ALL to OFFLINE_SOFT"
$PSQL -BNe "UPDATE mysql_servers SET status = 'OFFLINE_SOFT', comment = 'proxysql-oc-helper-${VER}'"
$PSQL -BNe "LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;"
exit 0
fi
for h in $($OC -c downtimed|cut -d':' -f1); do
echo "Setting $h to OFFLINE_SOFT"
$PSQL -BNe "UPDATE mysql_servers SET status = 'OFFLINE_SOFT', comment = 'proxysql-oc-helper-${VER}' WHERE hostname = '$h'"
_status=$($PSQL -BNe "SELECT DISTINCT status FROM runtime_mysql_servers WHERE hostname = '$h'")
if [ "x${_status}" != 'xOFFLINE_SOFT' -a "x${_status}" != 'x' ]; then
$PSQL -BNe "LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;"
fi
done
_sql="SELECT hostname FROM mysql_servers WHERE status = 'OFFLINE_SOFT' AND comment LIKE 'proxysql-oc-helper-%' AND comment <> 'proxysql-oc-helper-${VER}'"
for h in $($PSQL -BNe "${_sql}"); do
echo "Setting $h back to ONLINE"
$PSQL -BNe "UPDATE mysql_servers SET status = 'ONLINE' WHERE hostname = '$h'"
$PSQL -BNe "LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.