#! /bin/sh #---------------------------------------------------- #shell used to setup the host part (network, cgroup) #while starting a vzgot Virtual Host #This shell is called from the vzgot executable # vzgot boot cont_name # #---------------------------------------------------- #Syntaxe #vzgot.open VE_name VE_pid [base_dir] # VE_name is the container dir name # HS_pid is the vzgot container master process # VE_pid is the container main process ID as seen # by the host # base_dir is this application root directory # used for devel only. #---------------------------------------------------- CONTNAME=$1 HSPID=$2 VEPID=$3 BASE=$4 #---------------------------------------------------- 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 #---------------------------------------------------- #Using cgroup if available and operational if [ -f $CGROUP/tasks ] ; then ln -nsf $CGROUP/$VEPID $BASE/$VZLIB/vzdir/$CONTNAME/cgroup if [ -d $BASE/$VZLIB/vzdir/$CONTNAME/cgroup.d ] ; then for c in `ls $BASE/$VZLIB/vzdir/$CONTNAME/cgroup.d` do #setting container limits sed 's/#.*//g' $BASE/$VZLIB/vzdir/$CONTNAME/cgroup.d/$c | \ grep -v '^[[:space:]]*$' > /tmp/$c.$$ exec 5< /tmp/$c.$$ while read -r -u 5 COMMAND do echo $COMMAND > $BASE/$VZLIB/vzdir/$CONTNAME/cgroup/$c done exec 5<&- rm -fr /tmp/$c.$$ done fi fi #---------------------------------------------------- #to be sure to start fresh with veth pair ip link del To_$HSPID > /dev/null 2>&1 #creation the veth pair. ip link add name To_$HSPID type veth peer name From_$HSPID ret=$? if [ $ret -ne 0 ]; then echo "vzgot.init, unable to create veth To_$HSPID/From_$HSPID pair" exit $ret fi #activating vteh HOST interface ifconfig To_$HSPID up ret=$? if [ $ret -ne 0 ]; then echo "vzgot.init, unable to activate veth HOST part" exit $ret fi #linking HOST vteh to bridge brctl addif $BRIDGENAME To_$HSPID ret=$? if [ $ret -ne 0 ]; then echo "vzgot.init, unable to link veth HOST part to bridge" exit $ret fi #giving the "from" part of the pair to VZ ip link set From_$HSPID netns $VEPID if [ $ret -ne 0 ]; then echo "vzgot.init, unable to give From_$HSPID veth pair to VZ process" exit $ret fi #---------------------------------------------------- #lets prepare all routing $BASE/$VZLIB/shell/vzgot.net $CONTNAME assign $BASE #---------------------------------------------------- exit 0