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