X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=initscripts%2Fsliceimage;h=8fee05c5eb560fb228cd9be35c081b7e249d7e67;hb=6c7069ff27b62cf9e34061c57e0734e4fb64b393;hp=0785caafed504ae144ca78b2bfdf79b50c85c78c;hpb=d64cacafef993e0ed06c398e22a17e6ecd1a2893;p=vserver-reference.git diff --git a/initscripts/sliceimage b/initscripts/sliceimage index 0785caa..8fee05c 100755 --- a/initscripts/sliceimage +++ b/initscripts/sliceimage @@ -1,16 +1,15 @@ #!/bin/bash # -# vserver-reference Updates VServer reference -# # Load before nm, vcached, and vservers # chkconfig: 3 60 80 -# description: Builds VServer reference image +# description: Update slice images # # Mark Huang # Copyright (C) 2004 The Trustees of Princeton University # -# $Id$ -# + +# Source function library. +. /etc/init.d/functions case "$1" in start|restart|reload) @@ -26,9 +25,6 @@ case "$1" in ;; esac -# Source function library. -. /etc/init.d/functions - # VServer definitions init_paths="/usr/lib64/util-vserver/util-vserver-vars /usr/lib/util-vserver/util-vserver-vars" for init_path in $init_paths ; do @@ -41,7 +37,7 @@ exec 3>&1 exec 4>&2 # Redirect stdout and stderr to a log file -exec >>/var/log/vserver-reference.log +exec >>/var/log/sliceimage exec 2>&1 echo "--- STARTING $(date) ---" >&3 2>&4 @@ -65,26 +61,26 @@ setattr --barrier "$__DEFAULT_VSERVERDIR" # conserving space by linking and not copying unified files. if [ -f /proc/virtual/info ] ; then - x=$[ 16#`awk '/^VCIKernel:/ { print $2 }' /proc/virtual/info` ]; - y=$[ (x >> 9) & 1] - if test "$y" = 1 ; then - # COW support - find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --iunlink - else - # no COW; - find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --~iunlink - fi + x=$[ 16#`awk '/^VCIKernel:/ { print $2 }' /proc/virtual/info` ]; + y=$[ (x >> 9) & 1] + if test "$y" = 1 ; then + # COW support + find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --iunlink + else + # no COW; + find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --~iunlink + fi fi # Build reference images for system slices # xxx if several instances of systemslices get installed, only one gets instanciated -for systemvserver in "$__DEFAULT_VSERVERDIR/.vstub/"*/*.cloned ; do +for systemslice in "$__DEFAULT_VSERVERDIR/.vstub/"*/*.cloned ; do # e.g. NAME=planetflow - NAME=$(basename $systemvserver .cloned) - DIR=$(dirname $systemvserver) + NAME=$(basename $systemslice .cloned) + DIR=$(dirname $systemslice) # e.g. SLICEFAMILY=planetlab-f8-i386 - SLICEFAMILY=$(cat $systemvserver) + SLICEFAMILY=$(cat $systemslice) # deduce the actual name used in .vref by replacing the first part of slice-family # (pldistro) with the slice name # e.g. VREFNAME=planetflow-f8-i386 @@ -98,45 +94,45 @@ for systemvserver in "$__DEFAULT_VSERVERDIR/.vstub/"*/*.cloned ; do [ -n "$FORCE" ] && message=Force-building # Copy base reference image - echo -n $"$message VServer reference image for $NAME in $VREFNAME: " >&3 2>&4 - - # Build in temporary directory - mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp" - TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX") - mkdir -p "$__DEFAULT_VSERVERDIR/.vref" - - # build the systemvserver from the one it was originally cloned from - FAMILYREF="$__DEFAULT_VSERVERDIR/.vref/$SLICEFAMILY" - if [ -d "$FAMILYREF" ] ; then - "$_VCLONE" "$FAMILYREF"/ "$TMP"/ - RETVAL=$? - else - RETVAL=1 - fi + echo -n $"$message slice image for $NAME in $VREFNAME: " >&3 2>&4 + + # Build in temporary directory + mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp" + TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX") + mkdir -p "$__DEFAULT_VSERVERDIR/.vref" + + # build the systemslice from the one it was originally cloned from + FAMILYREF="$__DEFAULT_VSERVERDIR/.vref/$SLICEFAMILY" + if [ -d "$FAMILYREF" ] ; then + "$_VCLONE" "$FAMILYREF"/ "$TMP"/ + RETVAL=$? + else + RETVAL=1 + fi - # merge the stub with the reference to get the system vserver - if [ $RETVAL -eq 0 ] ; then - (cd "$DIR/$NAME"/ && find . | cpio -m -d -u -p "$TMP"/) - RETVAL=$? - fi + # merge the stub with the reference to get the system slice + if [ $RETVAL -eq 0 ] ; then + (cd "$DIR/$NAME"/ && find . | cpio -m -d -u -p "$TMP"/) + RETVAL=$? + fi - # Clean RPM state - rm -f "$TMP/var/lib/rpm/__db"* - - # Move it to its permanent location when complete - if [ $RETVAL -eq 0 ] ; then - # if in force mode, cleanup - [ -d "$VREFPATH" ] && rm -rf "$VREFPATH" - mv "$TMP" "$VREFPATH" - success >&3 2>&4 - else - rm -rf "$TMP" - failure >&3 2>&4 - fi - echo >&3 2>&4 + # Clean RPM state + rm -f "$TMP/var/lib/rpm/__db"* + + # Move it to its permanent location when complete + if [ $RETVAL -eq 0 ] ; then + # if in force mode, cleanup + [ -d "$VREFPATH" ] && rm -rf "$VREFPATH" + mv "$TMP" "$VREFPATH" + success >&3 2>&4 + else + rm -rf "$TMP" + failure >&3 2>&4 + fi + echo >&3 2>&4 done -echo -n $"Updating VServer reference images: " >&3 2>&4 +echo -n $"Updating slice images: " >&3 2>&4 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"