#!/bin/bash
#--------------第一部分:变量及函数定义-----------------#
###Begin Variables define###
ssh_port=22
cmd=/sbin/ifconfig
vip=172.16.4.116
device=eth0:0
netmk=255.255.255.0
start_vip="${cmd} ${device} ${vip} netmask ${netmk} up"
stop_vip="${cmd} ${device} ${vip} netmask ${netmk} down"
###End Variables define###
###Begin Status Funciont###
status()
{
exit 0
}
###End Status Funciont###
###Begin Stop Or Stopssh Funciont###
stop()
{
exit 0
}
###End Stop Or Stopssh Funciont###
###Begin Start Funciont###
start()
{
/usr/bin/ssh -p ${ssh_port} ${ssh_user}@${orig_master_host} ""${stop_vip}""
/usr/bin/ssh -p ${ssh_port} ${ssh_user}@${new_master_host} ""${start_vip}""
exit 0
}
###End Start Funciont###
#--------------第一部分:变量及函数定义-----------------#
#--------------第二部分:命令行参数-----------------#
###Begin Get The Command-Line Parameters###
eval set -- "`getopt -a -q -o n -l command::,ssh_user:,orig_master_host:,orig_master_ip:,new_master_host:,new_master_ip: -- "$@"`"
if [ $? != 0 ] ; then echo "Terminating..." >&2 ;exit 1;fi
while true
do
case "$1" in
--command)
command="${2}";
shift;;
--ssh_user)
ssh_user="${2}";
shift;;
--orig_master_host)
orig_master_host="${2}";
shift;;
--orig_master_ip)
orig_master_ip="${2}";
shift;;
--new_master_host)
new_master_host="${2}";
shift;;
--new_master_ip)
new_master_ip="${2}";
shift;;
--)
shift;
break;;
esac
shift
done
###End Get The Command-Line Parameters###
#--------------第二部分:命令行参数-----------------#
#--------------第三部分:函数调用-----------------#
if [ "${command}" == "status" ];
then
status;
fi
if [ "${command}" == "stop" ] || [ "${command}" == "stopssh" ] ;
then
stop;
fi
if [ "${command}" == "start" ];
then
start;
fi
#--------------第三部分:函数调用-----------------#
shell 实现MHA的master_ip_failover
最新推荐文章于 2021-03-27 19:39:29 发布