Created
April 15, 2017 13:30
-
-
Save omega8cc/3b1fb183b7b6fcb1c8c5f56e36d0e8a7 to your computer and use it in GitHub Desktop.
Fix ProxySQL config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SHELL=/bin/bash | |
PATH=/usr/local/bin:/usr/local/sbin:/opt/local/bin:/usr/bin:/usr/sbin:/bin:/sbin | |
_NOSTRICT="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" | |
### | |
### Avoid too many questions | |
### | |
export DEBIAN_FRONTEND=noninteractive | |
if [ -z "${TERM+x}" ]; then | |
export TERM=vt100 | |
fi | |
source /root/.cluster.cnf | |
fix_pxy() { | |
idn="${_CLUSTER_PREFIX}web" | |
if [ -e "/vservers/${idn}/root/.my.proxysql_adm_pwd.txt" ]; then | |
_PROXYSQL_PASSWORD=$(cat /vservers/${idn}/root/.my.proxysql_adm_pwd.txt 2>&1) | |
for IP in "${_DB_NODE_IP[@]}"; do | |
pxyCmd="INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,comment) VALUES ('${IP}',11,3306,1000,'READWRITE');" | |
ssh ${_NOSTRICT} root@${_WEB_NODE_IP} "mysql -uadmin -p${_PROXYSQL_PASSWORD} -h127.0.0.1 -P6032 -e \"${pxyCmd}\"" | |
done | |
pxyCmd="LOAD MYSQL SERVERS TO RUNTIME;" | |
ssh ${_NOSTRICT} root@${_WEB_NODE_IP} "mysql -uadmin -p${_PROXYSQL_PASSWORD} -h127.0.0.1 -P6032 -e \"${pxyCmd}\"" | |
pxyCmd="SAVE MYSQL SERVERS TO DISK;" | |
ssh ${_NOSTRICT} root@${_WEB_NODE_IP} "mysql -uadmin -p${_PROXYSQL_PASSWORD} -h127.0.0.1 -P6032 -e \"${pxyCmd}\"" | |
else | |
echo "Missing file: /vservers/${idn}/root/.my.proxysql_adm_pwd.txt" | |
fi | |
} | |
fix_pxy | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment