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 . /usr/lib/util-vserver/util-vserver-vars
33 # Save stdout and stderr
37 # Redirect stdout and stderr to a log file
38 exec >>/var/log/vserver-reference.log
41 echo "--- STARTING $(date) ---" >&3 2>&4
43 # Parse PLC configuration
44 if [ -r /etc/planetlab/plc_config ] ; then
45 . /etc/planetlab/plc_config
49 PLC_BOOT_HOST="boot.planet-lab.org"
54 # Make sure the barrier bit is set
55 chmod 0000 "$__DEFAULT_VSERVERDIR"
56 setattr --barrier "$__DEFAULT_VSERVERDIR"
58 # Set the attribute to unlink so vclone does the right thing wrt to
59 # conserving space by linking and not copying unified files.
61 if [ -f /proc/virtual/info ] ; then
62 x=$[ 16#`awk '/^VCIKernel:/ { print $2 }' /proc/virtual/info` ];
64 if test "$y" = 1 ; then
66 find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --iunlink
69 find "$__DEFAULT_VSERVERDIR/.vref"/* -type f -print0 | xargs -0 setattr --~iunlink
74 # Build reference images for system slices
75 # xxx if several instances of systemslices get installed, only one gets instanciated
76 for systemvserver in "$__DEFAULT_VSERVERDIR/.vstub/"*/*.cloned ; do
77 # e.g. NAME=planetflow
78 NAME=$(basename $systemvserver .cloned)
79 DIR=$(dirname $systemvserver)
80 # e.g. SLICEFAMILY=planetlab-f8-i386
81 SLICEFAMILY=$(cat $systemvserver)
82 # deduce the actual name used in .vref by replacing the first part of slice-family
83 # (pldistro) with the slice name
84 # e.g. VREFNAME=planetflow-f8-i386
85 VREFNAME=$(echo $SLICEFAMILY | sed -e "s,^[^-]*-,$NAME-,")
87 # Copy base reference image
88 if [ ! -d "$__DEFAULT_VSERVERDIR/.vref/$VREFNAME" ] ; then
89 echo -n $"Building VServer reference image for $NAME in $VREFNAME: " >&3 2>&4
91 # Build in temporary directory
92 mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp"
93 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
94 mkdir -p "$__DEFAULT_VSERVERDIR/.vref"
96 # build the systemvserver from the one it was originally cloned from
97 REF="$__DEFAULT_VSERVERDIR/.vref/$SLICEFAMILY"
98 if [ -d "$REF" ] ; then
99 "$_VCLONE" "$REF"/ "$TMP"/
105 # merge the stub with the reference to get the system vserver
106 if [ $RETVAL -eq 0 ] ; then
107 (cd "$DIR/$NAME"/ && find . | cpio -m -d -u -p "$TMP"/)
112 rm -f "$TMP/var/lib/rpm/__db"*
114 # Move it to its permanent location when complete
115 if [ $RETVAL -eq 0 ] ; then
116 mv "$TMP" "$__DEFAULT_VSERVERDIR/.vref/$VREFNAME"
126 echo -n $"Updating VServer reference images: " >&3 2>&4
128 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
130 # Copy configuration files from host to slices
131 for file in /etc/hosts /etc/resolv.conf /etc/planetlab/node_id \
132 /etc/planetlab/plc_config* /etc/planetlab/php/* \
133 /etc/pki/rpm-gpg/* ; do
134 if [ -r $file ] ; then
135 for vroot in $VROOTS ; do
136 install -D -m 644 $file $vroot/$file
141 # Remove stale RPM locks
142 rm -f $vroot/var/lib/rpm/__db*
144 # (Re)install GPG signing keys
145 if [ -d /etc/pki/rpm-gpg ] ; then
146 for vroot in $VROOTS ; do
147 chroot $vroot rpm --allmatches -e gpg-pubkey || :
148 chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
152 # Old versions of the Boot Manager copied portions of the Boot CD to
153 # /mnt/cdrom/bootme, to support old scripts which assumed that the
154 # Boot CD was mounted even in production mode. Now, it just copies it
155 # to /usr/boot/cacert.pem. In any case, copy the boot server
156 # certificate to the place(s) where BootServerRequest expects to find
157 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
159 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
160 for cacert in $CACERT ; do
161 if [ -r $cacert ] ; then
162 for vroot in $VROOTS ; do
163 # Install boot server certificate
164 install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
165 echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
167 # Also install in /mnt/cdrom/bootme for backward compatibility
168 install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
169 echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER
176 echo "--- DONE $(date) ---" >&3 2>&4