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
39 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 # Build reference images for system slices
60 for lst in "$__DEFAULT_VSERVERDIR/system-packages/"*.lst ; do
61 NAME=$(basename $lst .lst)
63 # Copy base reference image
64 if [ ! -d "$__DEFAULT_VSERVERDIR/.vref/$NAME" ] ; then
65 echo -n $"Building VServer reference image for $NAME: " >&3 2>&4
67 # Build in temporary directory
68 mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp"
69 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
70 mkdir -p "$__DEFAULT_VSERVERDIR/.vref"
71 "$__PKGLIBDIR/vbuild" "$__DEFAULT_VSERVERDIR/.vref/default" "$TMP"
74 # Install/update additional packages
75 if [ $RETVAL -eq 0 ] ; then
76 pushd "$__DEFAULT_VSERVERDIR/system-packages" >/dev/null
77 xargs rpm --root "$TMP" --install < "$NAME.lst"
83 rm -f "$TMP/var/lib/rpm/__db"*
85 # Move it to its permanent location when complete
86 if [ $RETVAL -eq 0 ] ; then
87 mv "$TMP" "$__DEFAULT_VSERVERDIR/.vref/$NAME"
96 echo -n $"Updating VServer reference images: " >&3 2>&4
98 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
100 # Copy configuration files from host to slices
101 for file in /etc/hosts /etc/resolv.conf /etc/yum.conf /etc/planetlab/node_id \
102 /etc/planetlab/plc_config* /etc/planetlab/php/* \
103 /etc/pki/rpm-gpg/* ; do
104 if [ -r $file ] ; then
105 for vroot in $VROOTS ; do
106 install -D -m 644 $file $vroot/$file
111 # Remove stale RPM locks
112 rm -f $vroot/var/lib/rpm/__db*
114 # (Re)install GPG signing keys
115 if [ -d /etc/pki/rpm-gpg ] ; then
116 for vroot in $VROOTS ; do
117 chroot $vroot rpm --allmatches -e gpg-pubkey || :
118 chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
122 # Old versions of the Boot Manager copied portions of the Boot CD to
123 # /mnt/cdrom/bootme, to support old scripts which assumed that the
124 # Boot CD was mounted even in production mode. Now, it just copies it
125 # to /usr/boot/cacert.pem. In any case, copy the boot server
126 # certificate to the place(s) where BootServerRequest expects to find
127 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
129 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
130 for cacert in $CACERT ; do
131 if [ -r $cacert ] ; then
132 for vroot in $VROOTS ; do
133 # Install boot server certificate
134 install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
135 echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
137 # Also install in /mnt/cdrom/bootme for backward compatibility
138 install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
139 echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER
146 echo "--- DONE $(date) ---" >&3 2>&4