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
59 for systemvserver in "$__DEFAULT_VSERVERDIR/.vstub/"*.cloned ; do
60 NAME=$(basename $systemvserver .cloned)
62 # Copy base reference image
63 if [ ! -d "$__DEFAULT_VSERVERDIR/.vref/$NAME" ] ; then
64 echo -n $"Building VServer reference image for $NAME: " >&3 2>&4
66 # Build in temporary directory
67 mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp"
68 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
69 mkdir -p "$__DEFAULT_VSERVERDIR/.vref"
71 # build the systemvserver from the one it was originally cloned from
72 TYPE=$(cat $systemvserver)
73 REF="$__DEFAULT_VSERVERDIR/.vref/$TYPE"
74 "$_VCLONE" "$REF"/ "$TMP"/
77 # merge the stub with the reference to get the system vserver
78 if [ $RETVAL -eq 0 ] ; then
79 (cd "$__DEFAULT_VSERVERDIR/.vstub/$NAME"/ && find . | cpio -m -d -u -p "$TMP"/)
84 rm -f "$TMP/var/lib/rpm/__db"*
86 # Move it to its permanent location when complete
87 if [ $RETVAL -eq 0 ] ; then
88 mv "$TMP" "$__DEFAULT_VSERVERDIR/.vref/$NAME"
97 echo -n $"Updating VServer reference images: " >&3 2>&4
99 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
101 # Copy configuration files from host to slices
102 for file in /etc/hosts /etc/resolv.conf /etc/yum.conf /etc/planetlab/node_id \
103 /etc/planetlab/plc_config* /etc/planetlab/php/* \
104 /etc/pki/rpm-gpg/* ; do
105 if [ -r $file ] ; then
106 for vroot in $VROOTS ; do
107 install -D -m 644 $file $vroot/$file
112 # Remove stale RPM locks
113 rm -f $vroot/var/lib/rpm/__db*
115 # (Re)install GPG signing keys
116 if [ -d /etc/pki/rpm-gpg ] ; then
117 for vroot in $VROOTS ; do
118 chroot $vroot rpm --allmatches -e gpg-pubkey || :
119 chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
123 # Old versions of the Boot Manager copied portions of the Boot CD to
124 # /mnt/cdrom/bootme, to support old scripts which assumed that the
125 # Boot CD was mounted even in production mode. Now, it just copies it
126 # to /usr/boot/cacert.pem. In any case, copy the boot server
127 # certificate to the place(s) where BootServerRequest expects to find
128 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
130 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
131 for cacert in $CACERT ; do
132 if [ -r $cacert ] ; then
133 for vroot in $VROOTS ; do
134 # Install boot server certificate
135 install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
136 echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
138 # Also install in /mnt/cdrom/bootme for backward compatibility
139 install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
140 echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER
147 echo "--- DONE $(date) ---" >&3 2>&4