mysql_failover.sh
1.02 KB
#!/bin/bash
# how to run
# sh mysql_failover.sh 172.31.10.162 1.2.3.5 aws
orig_master_ip=$1
new_master_ip=$2
az=$3
echo "Start to do mysql failover"
echo "orig_master_ip:${orig_master_ip}"
echo "new_master_ip:${new_master_ip}"
echo "az:${az}"
read -p "Are you sure to do failover? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
result=`python scripts/tools/mysql_failover.py "${orig_master_ip}" "${new_master_ip}" "${az}"`
echo "script return correct response:\n${result}"
# ansible-playbook -i inventories/az1/hosts playbooks/yoho.dns.yml --extra-vars "db_test_read=1.2.3.5 db_test_write=1.2.3.5"
echo "start to reload dns"
ansible-playbook -i inventories/${az}/hosts playbooks/yoho.dns.yml --extra-vars "confirmation=DNS ${result}"
echo "start to reload cobar"
ansible-playbook -i inventories/${az}/hosts playbooks/cobar.reload.yml --extra-vars "confirmation=YES"