#! /bin/sh #---------------------------------------------------- #shell used to assign/remove route needed by #a container when container is started or stopped # #---------------------------------------------------- #Syntaxe #vzgot.net VE_name assign|remove [base_dir] # VE_name is the container dir name # "assign" to set container needed route # "remove" to reset container needed route # base_dir is this application root directory # used for devel only. #---------------------------------------------------- CONTNAME=$1 ACTION=$2 BASE=$3 #---------------------------------------------------- if ! [ -f $BASE/etc/vzgot/vzgot_config ] ; then echo "Missing vzgot config file" exit 1 #trouble trouble fi . $BASE/etc/vzgot/vzgot_config #specific container configuration override (if needed) if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config ] ; then $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config fi #---------------------------------------------------- FLINUX="RedHat" if [ -f $VZLIB/vzdir/$CONTNAME/linux ] ; then FLINUX=`cat $VZLIB/vzdir/$CONTNAME/linux` fi #lets prepare all routing according type of linux #RedHat beeing the default case "$FLINUX" in "*" | \ "RedHat" ) NETINFO="$BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/sysconfig/network-scripts" for f in $NETINFO/ifcfg-* do EXT=`basename $f | cut -d'-' -f2` case "$EXT" in "lo" ) #local interface, nothing to do ;; * ) ADDR=`grep IPADDR $f | cut -d'=' -f2` case "$ACTION" in "assign" ) #pre-emptive route assignation /sbin/route add $ADDR dev $BRIDGENAME ;; "remove" ) /sbin/route del $ADDR dev $BRIDGENAME ;; * ) echo "ACTION request '$ACTION' is unexpected!" ;; esac ;; esac done ;; "Debian" ) NETINFO="$BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/network" for ADDR in `grep address $NETINFO/interfaces | cut -d' ' -f2` do case "$ACTION" in "assign" ) #pre-emptive route assignation /sbin/route add $ADDR dev $BRIDGENAME ;; "remove" ) /sbin/route del $ADDR dev $BRIDGENAME ;; * ) echo "ACTION request '$ACTION' is unexpected!" ;; esac done ;; esac #---------------------------------------------------- exit 0