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.
60 find "$__DEFAULT_VSERVERDIR/.vref/*" -type f -print0 | xargs -0 setattr --iunlink
62 # Build reference images for system slices
63 # xxx if several instances of systemslices get installed, only one gets instanciated
64 for systemvserver in "$__DEFAULT_VSERVERDIR/.vstub/"*/*.cloned ; do
65 NAME=$(basename $systemvserver .cloned)
66 DIR=$(dirname $systemvserver)
68 # Copy base reference image
69 if [ ! -d "$__DEFAULT_VSERVERDIR/.vref/$NAME" ] ; then
70 echo -n $"Building VServer reference image for $NAME: " >&3 2>&4
72 # Build in temporary directory
73 mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp"
74 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
75 mkdir -p "$__DEFAULT_VSERVERDIR/.vref"
77 # build the systemvserver from the one it was originally cloned from
78 TYPE=$(cat $systemvserver)
79 REF="$__DEFAULT_VSERVERDIR/.vref/$TYPE"
80 if [ -d "$REF" ] ; then
81 "$_VCLONE" "$REF"/ "$TMP"/
87 # merge the stub with the reference to get the system vserver
88 if [ $RETVAL -eq 0 ] ; then
89 (cd "$DIR/$NAME"/ && find . | cpio -m -d -u -p "$TMP"/)
94 rm -f "$TMP/var/lib/rpm/__db"*
96 # Move it to its permanent location when complete
97 if [ $RETVAL -eq 0 ] ; then
98 mv "$TMP" "$__DEFAULT_VSERVERDIR/.vref/$NAME"
108 echo -n $"Updating VServer reference images: " >&3 2>&4
110 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
112 # Copy configuration files from host to slices
113 for file in /etc/hosts /etc/resolv.conf /etc/planetlab/node_id \
114 /etc/planetlab/plc_config* /etc/planetlab/php/* \
115 /etc/pki/rpm-gpg/* ; do
116 if [ -r $file ] ; then
117 for vroot in $VROOTS ; do
118 install -D -m 644 $file $vroot/$file
123 # Remove stale RPM locks
124 rm -f $vroot/var/lib/rpm/__db*
126 # (Re)install GPG signing keys
127 if [ -d /etc/pki/rpm-gpg ] ; then
128 for vroot in $VROOTS ; do
129 chroot $vroot rpm --allmatches -e gpg-pubkey || :
130 chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
134 # Old versions of the Boot Manager copied portions of the Boot CD to
135 # /mnt/cdrom/bootme, to support old scripts which assumed that the
136 # Boot CD was mounted even in production mode. Now, it just copies it
137 # to /usr/boot/cacert.pem. In any case, copy the boot server
138 # certificate to the place(s) where BootServerRequest expects to find
139 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
141 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
142 for cacert in $CACERT ; do
143 if [ -r $cacert ] ; then
144 for vroot in $VROOTS ; do
145 # Install boot server certificate
146 install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
147 echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
149 # Also install in /mnt/cdrom/bootme for backward compatibility
150 install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
151 echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER
158 echo "--- DONE $(date) ---" >&3 2>&4