#! /bin/bash #vzgot.redoall #------------------------------------------------------------------- #procedure to re-install a set of predefined container. #its purpose is to generate 'clean' container over and over #$1 is the file with the container list #$2 base_dir is this application root directory # used for devel only. #container list format is # container_name distrinution architecture #------------------------------------------------------------------- LIST=$1 BASE=$2 #=================================================================== #lock procedure lockproc() { LOCKFILE=/var/lock/`basename $0`.$1.lck trap "rm -f $LOCKFILE ; exit 1" 1 2 3 15 if (set -C; : > $LOCKFILE) 2> /dev/null ; then echo $$ >> $LOCKFILE else echo "Another '`basename $0` $1' is running, existing at once!" echo "remove $LOCKFILE, if it is not the case" rm -f $LOCKFILE exit 0; fi } #------------------------------------------------------------------- #abort procedure abort () { echo "$1" rm -f $LOCKFILE exit 1; } #=================================================================== #main process #=================================================================== #locking building process lockproc $1 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 #------------------------------------------------------------------- #is the list file file existing if [ -f $BASE/etc/vzgot/$LIST ] ; then cat $BASE/etc/vzgot/$LIST | sed 's/#.*//g' | grep -v '^[[:space:]]*$' > /tmp/redo.$$ exec 5< /tmp/redo.$$ while read -r -u 5 CONTNAME REMAINING do if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/first.pid ] ; then vzgot shutdown $CONTNAME while [ -f $BASE/$VZLIB/vzdir/$CONTNAME/first.pid ] do sleep 1 done fi if [ -d $BASE/$VZLIB/vzdir/$CONTNAME ] ; then vzgot destroy $CONTNAME fi vzgot.mksrvz $CONTNAME done exec 5<&- rm -fr /tmp/redo.$$ fi rm -f $LOCKFILE