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 # Parse PLC configuration
34 if [ -r /etc/planetlab/plc_config ] ; then
35 . /etc/planetlab/plc_config
39 PLC_BOOT_HOST="boot.planet-lab.org"
42 # Save stdout and stderr
46 # Redirect stdout and stderr to a log file
48 exec &>/var/log/vserver-reference.log
52 # Make sure the barrier bit is set
53 chmod 0000 "$__DEFAULT_VSERVERDIR"
54 setattr --barrier "$__DEFAULT_VSERVERDIR"
56 # Build reference images for system slices
58 for lst in "$__DEFAULT_VSERVERDIR/system-packages/"*.lst ; do
59 NAME=$(basename $lst .lst)
61 # Copy base reference image
62 if [ ! -d "$__DEFAULT_VSERVERDIR/.vref/$NAME" ] ; then
63 echo -n $"Building VServer reference image for $NAME: " >&3 2>&4
65 # Build in temporary directory
66 mkdir -p "$__DEFAULT_VSERVERDIR/.vtmp"
67 TMP=$(mktemp -d "$__DEFAULT_VSERVERDIR/.vtmp/$NAME.XXXXXX")
68 mkdir -p "$__DEFAULT_VSERVERDIR/.vref"
69 "$__PKGLIBDIR/vbuild" "$__DEFAULT_VSERVERDIR/.vref/default" "$TMP"
72 # Install/update additional packages
73 if [ $RETVAL -eq 0 ] ; then
74 pushd "$__DEFAULT_VSERVERDIR/system-packages" >/dev/null
75 xargs rpm --root "$TMP" --install < "$NAME.lst"
81 rm -f "$TMP/var/lib/rpm/__db"*
83 # Move it to its permanent location when complete
84 if [ $RETVAL -eq 0 ] ; then
85 mv "$TMP" "$__DEFAULT_VSERVERDIR/.vref/$NAME"
94 echo -n $"Updating VServer reference images: " >&3 2>&4
96 VROOTS="$__DEFAULT_VSERVERDIR/.vref/* $__DEFAULT_VSERVERDIR/.vcache/* $__DEFAULT_VSERVERDIR/${PLC_SLICE_PREFIX}_*"
98 # Copy configuration files from host to slices
99 for file in /etc/hosts /etc/resolv.conf /etc/yum.conf /etc/planetlab/node_id \
100 /etc/planetlab/plc_config* /etc/planetlab/php/* \
101 /etc/pki/rpm-gpg/* ; do
102 if [ -r $file ] ; then
103 for vroot in $VROOTS ; do
104 install -D -m 644 $file $vroot/$file
109 # Remove stale RPM locks
110 rm -f $vroot/var/lib/rpm/__db*
112 # (Re)install GPG signing keys
113 if [ -d /etc/pki/rpm-gpg ] ; then
114 for vroot in $VROOTS ; do
115 chroot $vroot rpm --allmatches -e gpg-pubkey || :
116 chroot $vroot rpm --import /etc/pki/rpm-gpg/* || :
120 # Old versions of the Boot Manager copied portions of the Boot CD to
121 # /mnt/cdrom/bootme, to support old scripts which assumed that the
122 # Boot CD was mounted even in production mode. Now, it just copies it
123 # to /usr/boot/cacert.pem. In any case, copy the boot server
124 # certificate to the place(s) where BootServerRequest expects to find
125 # it (/usr/boot/cacert.pem by default, /mnt/cdrom/bootme in old
127 CACERT="/usr/boot/cacert.pem /mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem"
128 for cacert in $CACERT ; do
129 if [ -r $cacert ] ; then
130 for vroot in $VROOTS ; do
131 # Install boot server certificate
132 install -D -m 644 $cacert $vroot/usr/boot/cacert.pem
133 echo $PLC_BOOT_HOST > $vroot/usr/boot/boot_server
135 # Also install in /mnt/cdrom/bootme for backward compatibility
136 install -D -m 644 $cacert $vroot/mnt/cdrom/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
137 echo $PLC_BOOT_HOST > $vroot/mnt/cdrom/bootme/BOOTSERVER