3 # Load before nm, vcached, and vservers
5 # description: Update slice images
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2004 The Trustees of Princeton University
11 # Source function library.
12 . /etc/init.d/functions
23 echo $"Usage: $0 {start|stop|restart|reload|status|force}"
29 init_paths="/usr/lib64/util-vserver/util-vserver-vars /usr/lib/util-vserver/util-vserver-vars"
30 for init_path in $init_paths ; do
31 [ -f $init_path ] && { source $init_path ; break; }
33 [ "$PACKAGE_NAME" = "util-vserver" ] || echo "WARNING: could not find util-vserver init file among $init_paths"
35 # Save stdout and stderr
39 # Redirect stdout and stderr to a log file
40 exec >>/var/log/vserver-sliceimage
43 echo "--- STARTING $(date) ---" >&3 2>&4
45 # Parse PLC configuration
46 if [ -r /etc/planetlab/plc_config ] ; then
47 . /etc/planetlab/plc_config
51 PLC_BOOT_HOST="boot.planet-lab.org"
56 # Make sure the barrier bit is set
57 chmod 0000 "$__DEFAULT_VSERVERDIR"
58 setattr --barrier "$__DEFAULT_VSERVERDIR"
60 # Set the attribute to unlink so vclone does the right thing wrt to
61 # conserving space by linking and not copying unified files.
63 if [ -f /proc/virtual/info ] ; then
64 x=$[ 16#`awk '/^VCIKernel:/ { print $2 }' /proc/virtual/info` ];
66 if test "$y" = 1 ; then
68 find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --iunlink
71 find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --~iunlink
76 # Build reference images for system slices
77 # xxx if several instances of systemslices get installed, only one gets instanciated
78 for systemslice in "$__DEFAULT_VSERVERDIR/.vstub/"*/*.cloned ; do
79 # e.g. NAME=planetflow
80 NAME=$(basename $systemslice .cloned)
81 DIR=$(dirname $systemslice)
82 # e.g. SLICEFAMILY=planetlab-f8-i386
83 SLICEFAMILY=$(cat $systemslice)
84 # deduce the actual name used in .vref by replacing the first part of slice-family
85 # (pldistro) with the slice name
86 # e.g. VREFNAME=planetflow-f8-i386
87 VREFNAME=$(echo $SLICEFAMILY | sed -e "s,^[^-]*-,$NAME-,")
89 VREFPATH="$__DEFAULT_VSERVERDIR/.vref/$VREFNAME"
91 # do not redo existing vref's unless force is mentioned
92 [ -z "$FORCE" -a -d "$VREFPATH" ] && continue
93 [ -z "$FORCE" ] && message=Building
94 [ -n "$FORCE" ] && message=Force-building
96 # Copy base reference image
97 echo -n $"$message slice image for $NAME in $VREFNAME: " >&3 2>&4
99 # Build in temporary directory
100 mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp"
101 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
102 mkdir -p "$__DEFAULT_VSERVERDIR/.vref"
104 # build the systemslice from the one it was originally cloned from
105 FAMILYREF="$__DEFAULT_VSERVERDIR/.vref/$SLICEFAMILY"
106 if [ -d "$FAMILYREF" ] ; then
107 "$_VCLONE" "$FAMILYREF"/ "$TMP"/
113 # merge the stub with the reference to get the system slice
114 if [ $RETVAL -eq 0 ] ; then
115 (cd "$DIR/$NAME"/ && find . | cpio -m -d -u -p "$TMP"/)
120 rm -f "$TMP/var/lib/rpm/__db"*
122 # Move it to its permanent location when complete
123 if [ $RETVAL -eq 0 ] ; then
124 # if in force mode, cleanup
125 [ -d "$VREFPATH" ] && rm -rf "$VREFPATH"
126 mv "$TMP" "$VREFPATH"
135 echo -n $"Updating slice images: " >&3 2>&4
137 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
139 # Copy configuration files from host to slices
140 for file in /etc/hosts /etc/resolv.conf /etc/planetlab/node_id \
141 /etc/planetlab/plc_config* /etc/planetlab/php/* \
142 /etc/pki/rpm-gpg/* ; do
143 if [ -r $file ] ; then
144 for vroot in $VROOTS ; do
145 [ -d $vroot ] && install -D -m 644 $file $vroot/$file
151 for vroot in $VROOTS ; do
152 # NOTE: without this step, the 'rpm --allmatches' step can hang on boot
153 # Remove stale RPM locks from all VROOT dirs
154 [ -d $vroot ] && rm -f $vroot/var/lib/rpm/__db*
157 # (Re)install GPG signing keys
158 if [ -d /etc/pki/rpm-gpg ] ; then
159 for vroot in $VROOTS ; do
160 if [ -d $vroot ] ; then
161 chroot $vroot rpm --allmatches -e gpg-pubkey || :
162 chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
167 # Old versions of the Boot Manager copied portions of the Boot CD to
168 # /mnt/cdrom/bootme, to support old scripts which assumed that the
169 # Boot CD was mounted even in production mode. Now, it just copies it
170 # to /usr/boot/cacert.pem. In any case, copy the boot server
171 # certificate to the place(s) where BootServerRequest expects to find
172 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
174 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
175 for cacert in $CACERT ; do
176 if [ -r $cacert ] ; then
177 for vroot in $VROOTS ; do
178 if [ -d $vroot ] ; then
179 # Install boot server certificate
180 install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
181 echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
183 # Also install in /mnt/cdrom/bootme for backward compatibility
184 install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
185 echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER
193 echo "--- DONE $(date) ---" >&3 2>&4