Attachment 'lvs-helper.sh'

Download

#!/bin/sh
###
#
# lvs-helper - check replication status then block/unblock slave from LVS
# Copyright (C) 2008 Anchor Systems - http://www.anchor.com.au/
#
# 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., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
###

# Runs the check_replication.pl script, and if the result is not OK adds a
# reject rule into the LVS_HELPER table to ensure the loadbalancer removes
# this slave from LVS. If the result is ok, flush table to add the slave
# back.

CHAIN="LVS_HELPER"

# Determine if we should even be running this script (e.g. for the standby
# which is running a slave)
if /usr/bin/mysqladmin variables | grep -q 'datadir.*hamysql'
then
        # this must be the master currently
        # remove any firewall blocking rules in case this used to be a slave
        /sbin/iptables -F $CHAIN
        exit 0
fi

# Run the check. Unfortunately we have to hard code the params.
OUTPUT=`/usr/local/sbin/check_replication.pl --slave localhost --slave-user XXXXX --slave-pass XXXXX --master-user XXXXX --master-pass XXXXX`
retval=$?

# Only block LVS if the result is critical or an error
if [ "$retval" -gt 1 ]
then
        # Only insert one rule. Output always shows two lines of headers
        if [ "`/sbin/iptables -L $CHAIN -n | /usr/bin/wc -l`" -le 2 ]
        then
                /sbin/iptables -I $CHAIN -j REJECT
                #echo "Slave is out of sync, adding firewall rule to block loadbalancer:"
                #echo "$OUTPUT"
                #/usr/bin/mysql -e "show slave status\G"
        fi
else
        if [ "`/sbin/iptables -L $CHAIN -n | /usr/bin/wc -l`" -gt 2 ]
        then
                /sbin/iptables -F $CHAIN
                #echo "Slave is back in sync, removing firewall rule blocking loadbalancer."
        fi
fi

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2013-05-31 11:14:57, 8.0 KB) [[attachment:IPaddr2_vlan.sh]]
  • [get | view] (2013-05-31 11:14:58, 361.3 KB) [[attachment:LCA2008-talk.odp]]
  • [get | view] (2013-05-31 11:14:58, 832.2 KB) [[attachment:LCA2008-talk.pdf]]
  • [get | view] (2013-05-31 11:14:57, 3.7 KB) [[attachment:alter_mysql_slave]]
  • [get | view] (2013-05-31 11:14:57, 3.7 KB) [[attachment:alter_mysql_slave.sh]]
  • [get | view] (2013-05-31 11:14:57, 1.5 KB) [[attachment:authkeys]]
  • [get | view] (2013-05-31 11:14:57, 1.5 KB) [[attachment:authkeys.txt]]
  • [get | view] (2013-05-31 11:14:58, 1.1 KB) [[attachment:check-drbd.sh]]
  • [get | view] (2013-05-31 11:14:57, 11.4 KB) [[attachment:check_replication.pl]]
  • [get | view] (2013-05-31 11:14:57, 6.1 KB) [[attachment:cib.xml.template]]
  • [get | view] (2013-05-31 11:14:58, 8.0 KB) [[attachment:db-export-mysqlstandby.pl]]
  • [get | view] (2013-05-31 11:14:57, 3.8 KB) [[attachment:drbd.conf.txt]]
  • [get | view] (2013-05-31 11:14:58, 1.3 KB) [[attachment:drbddisk.sh]]
  • [get | view] (2013-05-31 11:14:57, 1.5 KB) [[attachment:ha.cf.txt]]
  • [get | view] (2013-05-31 11:14:58, 9.0 KB) [[attachment:init_mysql_slave.pl]]
  • [get | view] (2013-05-31 11:14:58, 1.2 KB) [[attachment:logd.cf.txt]]
  • [get | view] (2013-05-31 11:14:58, 2.2 KB) [[attachment:lvs-helper.sh]]
  • [get | view] (2013-05-31 11:14:57, 1.8 KB) [[attachment:my.cnf.txt]]
  • [get | view] (2013-05-31 11:14:57, 2.2 KB) [[attachment:myslave.cnf.txt]]
  • [get | view] (2013-05-31 11:14:57, 5.5 KB) [[attachment:mysqld.sh]]
  • [get | view] (2013-05-31 11:14:58, 2.0 KB) [[attachment:mysqlslave.cnf.txt]]
  • [get | view] (2013-05-31 11:14:57, 5.7 KB) [[attachment:mysqlslaved.sh]]
  • [get | view] (2013-05-31 11:14:57, 3.5 KB) [[attachment:write_heartbeat.pl]]

You are not allowed to attach a file to this page.