#!/usr/bin/env bash
# filename: lvsreal.sh

DEFAULT_VIP=1.1.1.1

if [[ -z $INPUT_DOMAIN ]]
then
    VIP=${DEFAULT_VIP}
else
    VIP=$1
fi


source /etc/rc.d/init.d/functions

case "$1" in

    start)
        echo "[+] Start LVS of Real Server"

        ip addr add ${VIP}/32 dev lo 2>/dev/null
        action "ip address: ${VIP}"

        echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
        echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
        ;;

    stop)
        echo "[-] Stop LVS of Real Server"

        ip addr del ${VIP}/32 dev lo 2>/dev/null
        action "ip address: ${VIP}"

        echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
        echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
        echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
        ;;

    *)
        echo "Usage: $(basename $0 .sh) {start | stop}"
        exit 1
esac
