3 # vserver-reference Updates VServer reference
5 # Load before nm, vcached, and vservers
7 # description: Builds VServer reference image
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2004 The Trustees of Princeton University
24 echo $"Usage: $0 {start|stop|restart|reload|status|force}"
29 # Source function library.
30 . /etc/init.d/functions
33 init_paths="/usr/lib64/util-vserver/util-vserver-vars /usr/lib/util-vserver/util-vserver-vars"
34 for init_path in $init_paths ; do
35 [ -f $init_path ] && { source $init_path ; break; }
37 [ "$PACKAGE_NAME" = "util-vserver" ] || echo "WARNING: could not find util-vserver init file among $init_paths"
39 # Save stdout and stderr
43 # Redirect stdout and stderr to a log file
44 exec >>/var/log/vserver-reference.log
47 echo "--- STARTING $(date) ---" >&3 2>&4
49 # Parse PLC configuration
50 if [ -r /etc/planetlab/plc_config ] ; then
51 . /etc/planetlab/plc_config
55 PLC_BOOT_HOST="boot.planet-lab.org"
60 # Make sure the barrier bit is set
61 chmod 0000 "$__DEFAULT_VSERVERDIR"
62 setattr --barrier "$__DEFAULT_VSERVERDIR"
64 # Set the attribute to unlink so vclone does the right thing wrt to
65 # conserving space by linking and not copying unified files.
67 if [ -f /proc/virtual/info ] ; then
68 x=$[ 16#`awk '/^VCIKernel:/ { print $2 }' /proc/virtual/info` ];
70 if test "$y" = 1 ; then
72 find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --iunlink
75 find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --~iunlink
80 # Build reference images for system slices
81 # xxx if several instances of systemslices get installed, only one gets instanciated
82 for systemvserver in "$__DEFAULT_VSERVERDIR/.vstub/"*/*.cloned ; do
83 # e.g. NAME=planetflow
84 NAME=$(basename $systemvserver .cloned)
85 DIR=$(dirname $systemvserver)
86 # e.g. SLICEFAMILY=planetlab-f8-i386
87 SLICEFAMILY=$(cat $systemvserver)
88 # deduce the actual name used in .vref by replacing the first part of slice-family
89 # (pldistro) with the slice name
90 # e.g. VREFNAME=planetflow-f8-i386
91 VREFNAME=$(echo $SLICEFAMILY | sed -e "s,^[^-]*-,$NAME-,")
93 VREFPATH="$__DEFAULT_VSERVERDIR/.vref/$VREFNAME"
95 # do not redo existing vref's unless force is mentioned
96 [ -z "$FORCE" -a -d "$VREFPATH" ] && continue
97 [ -z "$FORCE" ] && message=Building
98 [ -n "$FORCE" ] && message=Force-building
100 # Copy base reference image
101 echo -n $"$message VServer reference image for $NAME in $VREFNAME: " >&3 2>&4
103 # Build in temporary directory
104 mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp"
105 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
106 mkdir -p "$__DEFAULT_VSERVERDIR/.vref"
108 # build the systemvserver from the one it was originally cloned from
109 FAMILYREF="$__DEFAULT_VSERVERDIR/.vref/$SLICEFAMILY"
110 if [ -d "$FAMILYREF" ] ; then
111 "$_VCLONE" "$FAMILYREF"/ "$TMP"/
117 # merge the stub with the reference to get the system vserver
118 if [ $RETVAL -eq 0 ] ; then
119 (cd "$DIR/$NAME"/ && find . | cpio -m -d -u -p "$TMP"/)
124 rm -f "$TMP/var/lib/rpm/__db"*
126 # Move it to its permanent location when complete
127 if [ $RETVAL -eq 0 ] ; then
128 # if in force mode, cleanup
129 [ -d "$VREFPATH" ] && rm -rf "$VREFPATH"
130 mv "$TMP" "$VREFPATH"
139 echo -n $"Updating VServer reference images: " >&3 2>&4
141 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
143 # Copy configuration files from host to slices
144 for file in /etc/hosts /etc/resolv.conf /etc/planetlab/node_id \
145 /etc/planetlab/plc_config* /etc/planetlab/php/* \
146 /etc/pki/rpm-gpg/* ; do
147 if [ -r $file ] ; then
148 for vroot in $VROOTS ; do
149 [ -d $vroot ] && install -D -m 644 $file $vroot/$file
155 for vroot in $VROOTS ; do
156 # NOTE: without this step, the 'rpm --allmatches' step can hang on boot
157 # Remove stale RPM locks from all VROOT dirs
158 [ -d $vroot ] && rm -f $vroot/var/lib/rpm/__db*
161 # (Re)install GPG signing keys
162 if [ -d /etc/pki/rpm-gpg ] ; then
163 for vroot in $VROOTS ; do
164 if [ -d $vroot ] ; then
165 chroot $vroot rpm --allmatches -e gpg-pubkey || :
166 chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
171 # Old versions of the Boot Manager copied portions of the Boot CD to
172 # /mnt/cdrom/bootme, to support old scripts which assumed that the
173 # Boot CD was mounted even in production mode. Now, it just copies it
174 # to /usr/boot/cacert.pem. In any case, copy the boot server
175 # certificate to the place(s) where BootServerRequest expects to find
176 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
178 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
179 for cacert in $CACERT ; do
180 if [ -r $cacert ] ; then
181 for vroot in $VROOTS ; do
182 if [ -d $vroot ] ; then
183 # Install boot server certificate
184 install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
185 echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
187 # Also install in /mnt/cdrom/bootme for backward compatibility
188 install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
189 echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER
197 echo "--- DONE $(date) ---" >&3 2>&4