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
22 echo $"Usage: $0 {start|stop|restart|status}"
27 # Source function library.
28 . /etc/init.d/functions
31 init_paths="/usr/lib64/util-vserver/util-vserver-vars /usr/lib/util-vserver/util-vserver-vars"
32 for init_path in $init_paths ; do
33 [ -f $init_path ] && { source $init_path ; break; }
35 [ "$PACKAGE_NAME" = "util-vserver" ] || echo "WARNING: could not find util-vserver init file among $init_paths"
37 # Save stdout and stderr
41 # Redirect stdout and stderr to a log file
42 exec >>/var/log/vserver-reference.log
45 echo "--- STARTING $(date) ---" >&3 2>&4
47 # Parse PLC configuration
48 if [ -r /etc/planetlab/plc_config ] ; then
49 . /etc/planetlab/plc_config
53 PLC_BOOT_HOST="boot.planet-lab.org"
58 # Make sure the barrier bit is set
59 chmod 0000 "$__DEFAULT_VSERVERDIR"
60 setattr --barrier "$__DEFAULT_VSERVERDIR"
62 # Set the attribute to unlink so vclone does the right thing wrt to
63 # conserving space by linking and not copying unified files.
65 if [ -f /proc/virtual/info ] ; then
66 x=$[ 16#`awk '/^VCIKernel:/ { print $2 }' /proc/virtual/info` ];
68 if test "$y" = 1 ; then
70 find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --iunlink
73 find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --~iunlink
78 # Build reference images for system slices
79 # xxx if several instances of systemslices get installed, only one gets instanciated
80 for systemvserver in "$__DEFAULT_VSERVERDIR/.vstub/"*/*.cloned ; do
81 # e.g. NAME=planetflow
82 NAME=$(basename $systemvserver .cloned)
83 DIR=$(dirname $systemvserver)
84 # e.g. SLICEFAMILY=planetlab-f8-i386
85 SLICEFAMILY=$(cat $systemvserver)
86 # deduce the actual name used in .vref by replacing the first part of slice-family
87 # (pldistro) with the slice name
88 # e.g. VREFNAME=planetflow-f8-i386
89 VREFNAME=$(echo $SLICEFAMILY | sed -e "s,^[^-]*-,$NAME-,")
91 # Copy base reference image
92 if [ ! -d "$__DEFAULT_VSERVERDIR/.vref/$VREFNAME" ] ; then
93 echo -n $"Building VServer reference image for $NAME in $VREFNAME: " >&3 2>&4
95 # Build in temporary directory
96 mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp"
97 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
98 mkdir -p "$__DEFAULT_VSERVERDIR/.vref"
100 # build the systemvserver from the one it was originally cloned from
101 REF="$__DEFAULT_VSERVERDIR/.vref/$SLICEFAMILY"
102 if [ -d "$REF" ] ; then
103 "$_VCLONE" "$REF"/ "$TMP"/
109 # merge the stub with the reference to get the system vserver
110 if [ $RETVAL -eq 0 ] ; then
111 (cd "$DIR/$NAME"/ && find . | cpio -m -d -u -p "$TMP"/)
116 rm -f "$TMP/var/lib/rpm/__db"*
118 # Move it to its permanent location when complete
119 if [ $RETVAL -eq 0 ] ; then
120 mv "$TMP" "$__DEFAULT_VSERVERDIR/.vref/$VREFNAME"
130 echo -n $"Updating VServer reference images: " >&3 2>&4
132 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
134 # Copy configuration files from host to slices
135 for file in /etc/hosts /etc/resolv.conf /etc/planetlab/node_id \
136 /etc/planetlab/plc_config* /etc/planetlab/php/* \
137 /etc/pki/rpm-gpg/* ; do
138 if [ -r $file ] ; then
139 for vroot in $VROOTS ; do
140 [ -d $vroot ] && install -D -m 644 $file $vroot/$file
146 for vroot in $VROOTS ; do
147 # NOTE: without this step, the 'rpm --allmatches' step can hang on boot
148 # Remove stale RPM locks from all VROOT dirs
149 [ -d $vroot ] && rm -f $vroot/var/lib/rpm/__db*
152 # (Re)install GPG signing keys
153 if [ -d /etc/pki/rpm-gpg ] ; then
154 for vroot in $VROOTS ; do
155 if [ -d $vroot ] ; then
156 chroot $vroot rpm --allmatches -e gpg-pubkey || :
157 chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
162 # Old versions of the Boot Manager copied portions of the Boot CD to
163 # /mnt/cdrom/bootme, to support old scripts which assumed that the
164 # Boot CD was mounted even in production mode. Now, it just copies it
165 # to /usr/boot/cacert.pem. In any case, copy the boot server
166 # certificate to the place(s) where BootServerRequest expects to find
167 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
169 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
170 for cacert in $CACERT ; do
171 if [ -r $cacert ] ; then
172 for vroot in $VROOTS ; do
173 if [ -d $vroot ] ; then
174 # Install boot server certificate
175 install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
176 echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
178 # Also install in /mnt/cdrom/bootme for backward compatibility
179 install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
180 echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER
188 echo "--- DONE $(date) ---" >&3 2>&4