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/default" -type f -print0 | xargs -0 setattr --iunlink
69 find "$__DEFAULT_VSERVERDIR/.vref/default" -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 NAME=$(basename $systemvserver .cloned)
78 DIR=$(dirname $systemvserver)
80 # Copy base reference image
81 if [ ! -d "$__DEFAULT_VSERVERDIR/.vref/$NAME" ] ; then
82 echo -n $"Building VServer reference image for $NAME: " >&3 2>&4
84 # Build in temporary directory
85 mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp"
86 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
87 mkdir -p "$__DEFAULT_VSERVERDIR/.vref"
89 # build the systemvserver from the one it was originally cloned from
90 TYPE=$(cat $systemvserver)
91 REF="$__DEFAULT_VSERVERDIR/.vref/$TYPE"
92 if [ -d "$REF" ] ; then
93 "$_VCLONE" "$REF"/ "$TMP"/
99 # merge the stub with the reference to get the system vserver
100 if [ $RETVAL -eq 0 ] ; then
101 (cd "$DIR/$NAME"/ && find . | cpio -m -d -u -p "$TMP"/)
106 rm -f "$TMP/var/lib/rpm/__db"*
108 # Move it to its permanent location when complete
109 if [ $RETVAL -eq 0 ] ; then
110 mv "$TMP" "$__DEFAULT_VSERVERDIR/.vref/$NAME"
120 echo -n $"Updating VServer reference images: " >&3 2>&4
122 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
124 # Copy configuration files from host to slices
125 for file in /etc/hosts /etc/resolv.conf /etc/planetlab/node_id \
126 /etc/planetlab/plc_config* /etc/planetlab/php/* \
127 /etc/pki/rpm-gpg/* ; do
128 if [ -r $file ] ; then
129 for vroot in $VROOTS ; do
130 install -D -m 644 $file $vroot/$file
135 # Remove stale RPM locks
136 rm -f $vroot/var/lib/rpm/__db*
138 # (Re)install GPG signing keys
139 if [ -d /etc/pki/rpm-gpg ] ; then
140 for vroot in $VROOTS ; do
141 chroot $vroot rpm --allmatches -e gpg-pubkey || :
142 chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
146 # Old versions of the Boot Manager copied portions of the Boot CD to
147 # /mnt/cdrom/bootme, to support old scripts which assumed that the
148 # Boot CD was mounted even in production mode. Now, it just copies it
149 # to /usr/boot/cacert.pem. In any case, copy the boot server
150 # certificate to the place(s) where BootServerRequest expects to find
151 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
153 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
154 for cacert in $CACERT ; do
155 if [ -r $cacert ] ; then
156 for vroot in $VROOTS ; do
157 # Install boot server certificate
158 install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
159 echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
161 # Also install in /mnt/cdrom/bootme for backward compatibility
162 install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
163 echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER
170 echo "--- DONE $(date) ---" >&3 2>&4