- dynamically construct reference image on the target machine in a %post
authorMark Huang <mlhuang@cs.princeton.edu>
Mon, 11 Oct 2004 04:24:42 +0000 (04:24 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Mon, 11 Oct 2004 04:24:42 +0000 (04:24 +0000)
  scriplet, instead of building it on the build machine. This solves a
  couple of problems:

  1. RPM databases constructed on a RH9 machine could be corrupt on a
     FC2 machine because of the LD_ASSUME_KERNEL rpm/glibc NPTL bug.
  2. vserver-reference is no longer a 50 MB download. The reference
     image can be installed from the localhost yum cache most of the
     time.

  But introduces a couple of problems:

  1. If the %post scriplet fails, the whole installation fails
     with a warning, but without an error. Not having a complete
     vserver-reference build is a bad thing.
  2. Must zap RPM and YUM locks while installing.

vserver-reference.spec

index 40328d5..decb529 100644 (file)
@@ -1,6 +1,6 @@
 %define name vserver-reference
 %define version 3.0
-%define release 1.planetlab%{?date:.%{date}}
+%define release 2.planetlab%{?date:.%{date}}
 
 Vendor: PlanetLab
 Packager: PlanetLab Central <support@planet-lab.org>
@@ -16,180 +16,113 @@ License: GPL
 Group: Applications/System
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
 BuildArchitectures: noarch
-Requires: util-vserver
-AutoReqProv: no
-BuildRequires: e2fsprogs, yum
-
-%define debug_package %{nil}
+Requires: util-vserver, e2fsprogs, yum
 
 %description
 This package creates the virtual server (VServer) reference image used
 as the installation base for new PlanetLab slivers.
 
-%define vrootdir /vservers
-%define vrefdir %{vrootdir}/%{name}
-%define installroot $RPM_BUILD_ROOT%{vrefdir}
-
 %prep
 %setup -q
 
-# chattr, mknod, mount, yum all require root privileges. Yech.
-if [ $UID -ne 0 ] ; then
-    echo You must be root to build the %{name} package.
-    false
-fi
-
 %build
 
 %install
-# Running as root
-export PATH="$PATH:/sbin:/usr/sbin"
+rm -rf $RPM_BUILD_ROOT
 
-# Clean up
-if grep -q %{installroot}/proc /proc/mounts ; then
-    umount %{installroot}/proc
-fi
-if grep -q %{installroot}/dev/pts /proc/mounts ; then
-    umount %{installroot}/dev/pts
-fi
-chattr -R -i $RPM_BUILD_ROOT
+%clean
 rm -rf $RPM_BUILD_ROOT
 
-# Make /vservers
-mkdir -p $RPM_BUILD_ROOT%{vrootdir}
-chmod 000 $RPM_BUILD_ROOT%{vrootdir}
-chattr +t $RPM_BUILD_ROOT%{vrootdir}
+%post
+. /usr/lib/util-vserver/util-vserver-vars
+VROOT=$VROOTDIR/vserver-reference
 
-# Make /vservers/vserver-reference
-mkdir -p %{installroot}
-chattr -t %{installroot}
-chmod 755 %{installroot}
+# Pause vcached
+service vcached stop
 
-MAKEDEV ()
-{
-    if grep -q %{installroot}/dev/pts /proc/mounts ; then
-       umount %{installroot}/dev/pts
+# Remove old installation first
+if [ -d $VROOT ] ; then
+    if grep -q $VROOT/proc /proc/mounts ; then
+       umount $VROOT/proc
+    fi
+    if grep -q $VROOT/dev/pts /proc/mounts ; then
+       umount $VROOT/dev/pts
     fi
-    rm -rf %{installroot}/dev
-    mkdir -p %{installroot}/dev
-    mknod -m 666 %{installroot}/dev/null c 1 3
-    mknod -m 666 %{installroot}/dev/zero c 1 5
-    mknod -m 666 %{installroot}/dev/full c 1 7
-    mknod -m 644 %{installroot}/dev/random c 1 8
-    mknod -m 644 %{installroot}/dev/urandom c 1 9
-    mknod -m 666 %{installroot}/dev/tty c 5 0
-    mknod -m 666 %{installroot}/dev/ptmx c 5 2
-    touch %{installroot}/dev/hdv1
-}
-
-# Initialize /dev in reference image
-MAKEDEV
+    chattr -R -i $VROOT
+    rm -rf $VROOT
+fi
+
+$PKGLIBDIR/install-pre.sh vserver-reference
 
 # Mount /dev/pts in reference image
-mkdir -p %{installroot}/dev/pts
-mount -t devpts none %{installroot}/dev/pts
+mkdir -p $VROOT/dev/pts
+mount -t devpts none $VROOT/dev/pts
 
 # Mount /proc in reference image
-mkdir -p %{installroot}/proc
-mount -t proc none %{installroot}/proc
-
-# Create a dummy /etc/fstab in reference image
-mkdir -p %{installroot}/etc
-cat > %{installroot}/etc/fstab <<EOF
-# This fake fstab exists only to please df and linuxconf.
-/dev/hdv1      /       ext2    defaults        1 1
-EOF
+mkdir -p $VROOT/proc
+mount -t proc none $VROOT/proc
 
 # Prevent all locales from being installed in reference image
-mkdir -p %{installroot}/etc/rpm
-cat > %{installroot}/etc/rpm/macros <<EOF
+mkdir -p $VROOT/etc/rpm
+cat > $VROOT/etc/rpm/macros <<EOF
 %%_install_langs en_US:en
 %%_excludedocs 1
 %%__file_context_path /dev/null
 EOF
 
-# Initialize RPM database in reference image
-mkdir -p %{installroot}/var/lib/rpm
-rpm --root %{installroot} --initdb
-
-# XXX Get yum.conf from PlanetLabConf
-
-# Install RPMs in reference image
-yum -c ./yum.conf \
-%{?sslcertdir:--sslcertdir=%{sslcertdir}} \
---installroot=%{installroot} \
--y groupinstall VServer
-
-# Freshen any new RPMs
-find %{_topdir}/RPMS -type f | xargs rpm --root %{installroot} -F
-
-# Clean up /dev in reference image
-MAKEDEV
-
-# Configure authentication in reference image
-chroot %{installroot} authconfig --nostart --kickstart --enablemd5 --enableshadow || :
-
-# Disable all services in reference image
-chroot %{installroot} /bin/sh -c "chkconfig --list | awk '{ print \$1 }' | xargs -i chkconfig {} off"
-
-# Clean up
-if grep -q %{installroot}/proc /proc/mounts ; then
-    umount %{installroot}/proc
+# Zap some locks
+TMP=`mktemp -d /tmp/%{name}.XXXXXX`
+if [ -f /var/lock/rpm/transaction ] ; then
+    mv /var/lock/rpm/transaction $TMP
 fi
-if grep -q %{installroot}/dev/pts /proc/mounts ; then
-    umount %{installroot}/dev/pts
+if [ -f /var/run/yum.pid ] ; then
+    mv /var/run/yum.pid $TMP
 fi
 
-%clean
-# Running as root
-export PATH="$PATH:/sbin:/usr/sbin"
+# Initialize RPM database in reference image
+mkdir -p $VROOT/var/lib/rpm
+rpm --root $VROOT --initdb
 
-# Clean up
-if grep -q %{installroot}/proc /proc/mounts ; then
-    umount %{installroot}/proc
-fi
-if grep -q %{installroot}/dev/pts /proc/mounts ; then
-    umount %{installroot}/dev/pts
-fi
-chattr -R -i $RPM_BUILD_ROOT
-rm -rf $RPM_BUILD_ROOT
+# Install RPMs in reference image
+yum \
+--sslcertdir=/mnt/cdrom/bootme/cacert \
+--installroot=$VROOT \
+-y groupinstall VServer
 
-# Make sure the original user can remove the generated files
-if [ -n "$SUDO_UID" ] ; then
-    chown -R $SUDO_UID.$SUDO_GID .
-    for i in \
-       %{_topdir}/BUILD \
-       %{_topdir}/RPMS/noarch/%{name}-%{version}-%{release}.noarch.rpm \
-       %{_topdir}/RPMS/noarch \
-       %{_topdir}/RPMS/ \
-       %{_topdir}/SRPMS/%{name}-%{version}-%{release}.src.rpm \
-       %{_topdir}/SRPMS/ ; do
-      if [ -e $i ] ; then
-         chown $SUDO_UID.$SUDO_GID $i
-      fi
-    done
+# Restore locks
+if [ -f $TMP/transaction ] ; then
+    mv $TMP/transaction /var/lock/rpm
 fi
-
-%pre
-# 1 = install, 2 = upgrade/reinstall
-if [ $1 -eq 2 ] ; then
-    chattr -R -i %{vrefdir}
+if [ -f $TMP/yum.pid ] ; then
+    mv $TMP/yum.pid /var/run
 fi
+rmdir $TMP
 
-%post
 # Copy configuration files from host to reference image
 for file in /etc/hosts /etc/resolv.conf /etc/yum.conf ; do
     if [ -f $file ] ; then
-       echo $file | cpio -p -d -u %{vrefdir}
+       echo $file | cpio -p -d -u $VROOT
     fi
 done
 
-%preun
+# Clean up
+umount $VROOT/proc
+umount $VROOT/dev/pts
+
+$PKGLIBDIR/install-post.sh vserver-reference
+
+# Disable all services in reference image
+chroot $VROOT /bin/sh -c "chkconfig --list | awk '{ print \$1 }' | xargs -i chkconfig {} off"
+
+# Restart vcached
+service vcached start
 
 %files
 %defattr(-,root,root)
-%{vrefdir}
 
 %changelog
+* Sun Oct 10 2004 Mark Huang <mlhuang@cs.princeton.edu> 3.0-2.planetlab
+- dynamically install reference image
+
 * Tue Sep 14 2004 Mark Huang <mlhuang@cs.princeton.edu> 3.0-1.planetlab
 - initial build