Inserting VZGOT development tree within GIT
[safe/jmp/vzgot] / shell / vzgot.redoall
1 #! /bin/bash
2 #vzgot.redoall
3 #-------------------------------------------------------------------
4 #procedure to re-install a set of predefined container.
5 #its purpose is to generate 'clean' container over and over
6 #$1 is the file with the container list
7 #$2 base_dir is this application root directory
8 #   used for devel only.
9 #container list format is
10 # container_name distrinution architecture
11 #-------------------------------------------------------------------
12 LIST=$1
13 BASE=$2
14 #===================================================================
15 #lock procedure
16 lockproc()
17
18 {
19 LOCKFILE=/var/lock/`basename $0`.$1.lck
20
21 trap "rm -f $LOCKFILE ; exit 1" 1 2 3 15
22 if (set -C; : > $LOCKFILE) 2> /dev/null ; then
23     echo $$ >> $LOCKFILE
24   else
25     echo "Another '`basename $0` $1' is running, existing at once!"
26     echo "remove $LOCKFILE, if it is not the case"
27     rm -f $LOCKFILE
28     exit 0;
29   fi
30 }
31 #-------------------------------------------------------------------
32 #abort procedure
33 abort ()
34
35 {
36 echo "$1"
37 rm -f $LOCKFILE
38 exit 1;
39 }
40
41 #===================================================================
42 #main process
43 #===================================================================
44
45 #locking building process
46 lockproc $1
47
48 if ! [ -f $BASE/etc/vzgot/vzgot_config ] ; then
49   echo "Missing vzgot config file"
50   exit 1        #trouble trouble
51   fi
52 . $BASE/etc/vzgot/vzgot_config
53
54 #specific container configuration override (if needed)
55 if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config ] ; then
56   $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config
57   fi
58
59 #-------------------------------------------------------------------
60 #is the list file file existing
61 if [ -f $BASE/etc/vzgot/$LIST ] ; then
62   cat $BASE/etc/vzgot/$LIST | sed 's/#.*//g' | grep -v '^[[:space:]]*$' > /tmp/redo.$$
63   exec 5< /tmp/redo.$$
64   while read -r -u 5 CONTNAME REMAINING 
65     do
66     if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/first.pid ] ; then
67       vzgot shutdown $CONTNAME
68       while [ -f $BASE/$VZLIB/vzdir/$CONTNAME/first.pid ] 
69         do
70         sleep 1
71         done
72       fi
73     if [ -d $BASE/$VZLIB/vzdir/$CONTNAME ] ; then
74       vzgot destroy $CONTNAME 
75       fi
76     vzgot.mksrvz $CONTNAME
77     done
78   exec 5<&-
79   rm -fr /tmp/redo.$$
80   fi
81
82 rm -f $LOCKFILE