Release.
[safe/jmp/vzgot] / shell / vzgot.open
1 #! /bin/sh
2 #----------------------------------------------------
3 #shell used to setup the host part (network, cgroup)
4 #while starting a vzgot Virtual Host
5 #This shell is called from the vzgot executable
6 #       vzgot boot cont_name
7 #
8 #----------------------------------------------------
9 #Syntaxe
10 #vzgot.open VE_name VE_pid [base_dir]
11 #       VE_name is the container dir name
12 #       HS_pid is the vzgot container master process
13 #       VE_pid is the container main process ID as seen
14 #       by the host
15 #       base_dir is this application root directory
16 #       used for devel only.
17 #----------------------------------------------------
18 CONTNAME=$1
19 HSPID=$2
20 VEPID=$3
21 BASE=$4
22 #----------------------------------------------------
23 if ! [ -f $BASE/etc/vzgot/vzgot_config ] ; then
24   echo "Missing vzgot config file"
25   exit 1        #trouble trouble
26   fi
27 . $BASE/etc/vzgot/vzgot_config
28
29 #specific container configuration override (if needed)
30 if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config ] ; then
31   $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config
32   fi
33 #----------------------------------------------------
34 #Using cgroup if available and operational
35 if [ -f $CGROUP/tasks ] ; then
36   ln -nsf $CGROUP/$VEPID $BASE/$VZLIB/vzdir/$CONTNAME/cgroup
37   if [ -d $BASE/$VZLIB/vzdir/$CONTNAME/cgroup.d ] ; then
38     for c in `ls $BASE/$VZLIB/vzdir/$CONTNAME/cgroup.d`
39        do       #setting container limits
40        sed 's/#.*//g' $BASE/$VZLIB/vzdir/$CONTNAME/cgroup.d/$c | \
41                  grep -v '^[[:space:]]*$' > /tmp/$c.$$
42        exec 5< /tmp/$c.$$
43        while read -r -u 5 COMMAND
44          do
45          echo $COMMAND > $BASE/$VZLIB/vzdir/$CONTNAME/cgroup/$c
46          done
47        exec 5<&-
48        rm -fr /tmp/$c.$$
49        
50        done
51     fi
52   fi
53 #----------------------------------------------------
54 #to be sure to start fresh with veth pair
55 ip link del To_$HSPID > /dev/null 2>&1
56 #creation the veth pair.
57 ip link add name To_$HSPID type veth peer name From_$HSPID
58 ret=$?
59 if [ $ret -ne 0 ]; then
60   echo "vzgot.init, unable to create veth To_$HSPID/From_$HSPID pair"
61   exit $ret
62   fi
63 #activating vteh HOST interface
64 ifconfig To_$HSPID up
65 ret=$?
66 if [ $ret -ne 0 ]; then
67   echo "vzgot.init, unable to activate veth HOST part"
68   exit $ret
69   fi
70 #linking HOST vteh to bridge
71 brctl addif $BRIDGENAME To_$HSPID
72 ret=$?
73 if [ $ret -ne 0 ]; then
74   echo "vzgot.init, unable to link veth HOST part to bridge"
75   exit $ret
76   fi
77 #giving the "from" part of the pair to VZ
78 ip link set From_$HSPID netns $VEPID
79 if [ $ret -ne 0 ]; then
80   echo "vzgot.init, unable to give From_$HSPID veth pair to VZ process"
81   exit $ret
82   fi
83 #----------------------------------------------------
84 #lets prepare all routing
85 $BASE/$VZLIB/shell/vzgot.net $CONTNAME assign $BASE
86 #----------------------------------------------------
87 exit 0