Skip to content

Instantly share code, notes, and snippets.

@omega8cc
Created April 15, 2017 13:30
Show Gist options
  • Select an option

  • Save omega8cc/3b1fb183b7b6fcb1c8c5f56e36d0e8a7 to your computer and use it in GitHub Desktop.

Select an option

Save omega8cc/3b1fb183b7b6fcb1c8c5f56e36d0e8a7 to your computer and use it in GitHub Desktop.

Revisions

  1. omega8cc created this gist Apr 15, 2017.
    36 changes: 36 additions & 0 deletions fix_pxy.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/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