#!/bin/sh LANG=C date=$(date -d "today" +"%Y-%m-%d %H:%M:%S") function_bind_vip1() { /sbin/ifconfig eth0:ha1 61.1.1.3 broadcast 219.232.254.255 netmask 255.255.255.192 up /sbin/route add -host 61.1.1.3 dev eth0:ha1 } function_bind_vip2() { /sbin/ifconfig eth0:ha2 61.1.1.2 broadcast 219.232.254.255 netmask 255.255.255.192 up /sbin/route add -host 61.1.1.2 dev eth0:ha2 } function_restart_nginx() { kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid` } function_remove_vip1() { /sbin/ifconfig eth0:ha1 61.1.1.3 broadcast 219.232.254.255 netmask 255.255.255.192 down } function_remove_vip2() { /sbin/ifconfig eth0:ha2 61.1.1.2 broadcast 219.232.254.255 netmask 255.255.255.192 down } function_vip_arping1() { /sbin/arping -I eth0 -c 3 -s 61.1.1.3 61.1.1.1 > /dev/null 2>&1 } function_vip_arping2() { /sbin/arping -I eth0 -c 3 -s 61.1.1.2 61.1.1.1 > /dev/null 2>&1 } bind_time_vip1="N"; bind_time_vip2="N"; while true do httpcode_rip1=`/usr/bin/curl -o /dev/null -s -w %{http_code} http://61.1.1.5` httpcode_rip2=`/usr/bin/curl -o /dev/null -s -w %{http_code} http://61.1.1.4` if [ x$httpcode_rip1 == "x200" ]; then if [ $bind_time_vip1 == "N" ]; then function_bind_vip1 function_vip_arping1 function_restart_nginx bind_time_vip1="Y" fi function_vip_arping1 else if [ $bind_time_vip1 == "Y" ]; then function_remove_vip1 bind_time_vip1="N" fi fi if [ x$httpcode_rip2 == "x200" ]; then if [ $bind_time_vip2 == "Y" ]; then function_remove_vip2 bind_time_vip2="N" fi else if [ $bind_time_vip2 == "N" ]; then function_bind_vip2 function_vip_arping2 function_restart_nginx bind_time_vip2="Y" fi function_vip_arping2 fi sleep 5 done