Skip to content

Instantly share code, notes, and snippets.

@yoku0825
Created May 27, 2013 13:08
Show Gist options
  • Save yoku0825/5656972 to your computer and use it in GitHub Desktop.
Save yoku0825/5656972 to your computer and use it in GitHub Desktop.
真面目に動作確認していないです。 mysqladmin pingの結果から参照スレーブをよしなに切り替えてみる。
#!/usr/bin/env bash
###################################################################
# switch.sh - check mysqladmin ping and rewrite iptables
# Copyright (C) 2013 yoku0825
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA.
###################################################################
PATH=/bin:/usr/bin:/usr/mysql/5.5.31/bin:/sbin
DUMMY_IP="192.168.56.100"
REAL_IPS=("192.168.56.1" "192.168.56.2" "192.168.56.3")
if mysqladmin -h ${DUMMY_IP} -u root -pxxx ping > /dev/null 2>&1 ; then
exit 0
fi
iptables -t nat -D OUTPUT
for ((n = 0; n < ${#REAL_IPS[@]}; n++)) ; do
if mysqladmin -h ${REAL_IPS[n]} -u root -pxxx ping > /dev/null 2>&1 ; then
iptables -t nat -A -j DNAT --destination ${DUMMY_IP} --to-destination ${REAL_IPS[n]}
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment