Release.
[safe/jmp/vzgot] / shell / vzgot.destroy
1 #! /bin/sh
2 #----------------------------------------------------
3 #shell used to remove the root file system for a
4 #container.
5 #
6 #----------------------------------------------------
7 #Syntaxe
8 #vzgot.destroy VE_name
9 #       VE_name is the container dir name
10 #       base_dir is this application root directory
11 #       used for devel only.
12 #----------------------------------------------------
13 CONTNAME=$1
14 BASE=$2
15 #----------------------------------------------------
16 if ! [ -f $BASE/etc/vzgot/vzgot_config ] ; then
17   echo "Missing vzgot config file"
18   exit 1        #trouble trouble
19   fi
20 . $BASE/etc/vzgot/vzgot_config
21
22 #specific container configuration override (if needed)
23 if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config ] ; then
24   $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config
25   fi
26 #----------------------------------------------------
27 if [ ! -d $BASE/$VZLIB/vzdir/$CONTNAME ] ; then
28   echo "Container $CONTNAME not existing"
29   exit 1
30   fi
31
32 #----------------------------------------------------
33 #checking if container is up and running
34 if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/first.pid ] ; then
35   echo "Container $CONTNAME is up and running"
36   echo "Container must be stop first, try \"vzgot shutdown $CONTNAME\""
37   exit 2
38   fi
39 #----------------------------------------------------
40 if [ ! -z "$LVM" ] ; then
41   VZCONTNAME=`echo $CONTNAME | sed 's/\.//g' | sed 's/-//g'`
42   umount $BASE/$VZLIB/vzdir/$CONTNAME 
43   sed -i -e/"vzdir\/$CONTNAME"/d /etc/fstab
44   lvremove --quiet -f /dev/$LVM/$VZCONTNAME > /dev/null 2>&1
45   ret=$?
46   if [ $ret -ne 0 ]; then
47     echo "vzgot.destroy, unable to destroy LVM $VZCONTNAME with lvremove"
48     exit $ret
49     fi
50   fi
51 mv $BASE/$VZLIB/vzdir/$CONTNAME $BASE/$VZLIB/vzdir/$CONTNAME.$$
52 rm -fr $BASE/$VZLIB/vzdir/$CONTNAME.$$ &
53 exit 0