[Vserver] [PATCH] Add support for FAI build method

From: Sam Vilain <sam_at_vilain.net>
Date: Wed 27 Sep 2006 - 00:31:59 BST
Message-ID: <4519B86F.1060508@vilain.net>

The attached patch adds support for a FAI build method to util-vserver.
It is of proof-of-concept quality; it works, but could do with a bit of
refactoring.

This patch requires the "vserver" branch of FAI, browsable online at
http://svn.debian.org/wsvn/fai/people/mugwump/vserver/

Detection of this branch is still TO-DO.

---
 Makefile.in               |    1
 scripts/Makefile-files    |    1
 scripts/vserver-build     |    6 +
 scripts/vserver-build.fai |  182
++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 189 insertions(+), 1 deletion(-)

#! /bin/sh /usr/share/dpatch/dpatch-run
## 22_fai.dpatch by Sam Vilain <sam.vilain@catalyst.net.nz>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@
diff -urN util-vserver-0.30.210.orig/Makefile.in util-vserver-0.30.210/Makefile.in
--- util-vserver-0.30.210.orig/Makefile.in 2006-06-20 17:31:04.000000000 +1200
+++ util-vserver-0.30.210/Makefile.in 2006-06-20 17:30:02.000000000 +1200
@@ -1916,6 +1916,7 @@
                                 scripts/vserver-build.apt-rpm \
                                 scripts/vserver-build.skeleton \
                                 scripts/vserver-build.debootstrap \
+ scripts/vserver-build.fai \
                                 scripts/vserver-build.rpm \
                                 scripts/vserver-build.yum \
                                 scripts/vserver-build.functions \
--- util-vserver-0.30.210.orig/scripts/Makefile-files 2006-06-20 17:31:04.000000000 +1200
+++ util-vserver-0.30.210/scripts/Makefile-files 2006-06-20 17:30:02.000000000 +1200
@@ -41,6 +41,7 @@
                                 scripts/vserver-build.apt-rpm \
                                 scripts/vserver-build.skeleton \
                                 scripts/vserver-build.debootstrap \
+ scripts/vserver-build.fai \
                                 scripts/vserver-build.rpm \
                                 scripts/vserver-build.yum \
                                 scripts/vserver-build.functions \
diff -urN util-vserver-0.30.210.orig/scripts/vserver-build util-vserver-0.30.210/scripts/vserver-build
--- util-vserver-0.30.210.orig/scripts/vserver-build 2006-06-20 17:31:04.000000000 +1200
+++ util-vserver-0.30.210/scripts/vserver-build 2006-06-20 17:30:02.000000000 +1200
@@ -66,6 +66,10 @@
                      configuration file and calls an optional command then
     debootstrap ... -- -d <distribution> [-m <mirror>] [-s <script> ] [-- <debootstrap-options>*]
                      bootstraps the vserver with Debian's 'debootstrap' package
+ fai ... -- -f <fai_vserver> [-n <nfsroot>] [-d <fai_dir> ] [ -a ]
+ bootstraps the vserver with Debian Fully Automatic Installation
+ -a means skip confirmation prompt and final shell.
+
 
 Please report bugs to $PACKAGE_BUGREPORT"
     exit 0
@@ -126,7 +130,7 @@
 
 case x"$method" in
     (xlegacy) exec $_VSERVER_LEGACY "$VSERVER_NAME" build "$@" ;;
- (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm)
+ (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm|xfai)
                 . $__PKGLIBDIR/vserver-build.$method
                 ;;
     (x) panic $"No build-method specified";;
diff -urN util-vserver-0.30.210.orig/scripts/vserver-build.fai util-vserver-0.30.210/scripts/vserver-build.fai
--- util-vserver-0.30.210.orig/scripts/vserver-build.fai 1970-01-01 12:00:00.000000000 +1200
+++ util-vserver-0.30.210/scripts/vserver-build.fai 2006-06-20 17:30:18.000000000 +1200
@@ -0,0 +1,182 @@
+#
+# Copyright (C) 2006 Sam Vilain <sam.vilain@catalyst.net.nz>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+tmp=$(getopt -o '+d:+f:+n:+a' --long debug,pkgmgmt -n "$0" -- "$@") || exit 1
+eval set -- "$tmp"
+
+. "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
+
+DISTRIBUTION=:
+
+FAI_VSERVER=
+FAI_NFSROOT=/usr/lib/fai/nfsroot
+FAI_DIR=/usr/local/share/fai
+
+use_pkgmgmt=
+while true; do
+ case "$1" in
+ -f) FAI_VSERVER=$2; shift; ;;
+ -n) FAI_NFSROOT=$2; shift; ;;
+ -d) FAI_DIR=$2; shift; ;;
+ -a) AUTO=1; ;;
+ --debug) DEBUG=1; SH_DEBUG=-x; set -x;;
+ --) shift; break ;;
+ *) echo "vserver-build.fai: internal error: unrecognized option '$1'" >&2
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+getDistribution '' 1
+
+base.init
+base.initFilesystem "$OPTION_FORCE"
+
+setup_writeOption "$VSERVER_NAME"
+setup_writeInitialFstab
+
+test -z "$BUILD_INITPRE" || "$BUILD_INITPRE" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
+test -z "$1" || "$@"
+test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
+
+# if they specified a vserver where FAI is installed, then prefix its
+# root to the FAI_NFSROOT etc (unless they have already specified a
+# $ROOTDIR-relative path)
+REAL_ROOTDIR=`cd $ROOTDIR; pwd -P`
+REAL_VDIR=`cd $VDIR; pwd -P`
+echo "ROOTDIR is $REAL_ROOTDIR"
+echo "VDIR is $REAL_VDIR"
+if [ -n "$FAI_VSERVER" ]
+then
+ echo "FAI_VSERVER is $FAI_VSERVER"
+ if [ `expr "$FAI_NFSROOT" : "$REAL_ROOTDIR"` -eq 0 ]
+ then
+ FAI_NFSROOT="$REAL_ROOTDIR/$FAI_VSERVER$FAI_NFSROOT"
+ fi
+ if [ `expr "$FAI_DIR" : "$REAL_ROOTDIR"` -eq 0 ]
+ then
+ FAI_DIR="$REAL_ROOTDIR/$FAI_VSERVER$FAI_DIR"
+ fi
+fi
+echo "FAI_NFSROOT is $FAI_NFSROOT"
+echo "FAI_DIR is $FAI_DIR"
+FAI_ROOT=/tmp/target
+
+# setup a new filesystem namespace
+set -e
+#[ -d $FAI_NFSROOT/var/log/fai ] || mkdir $FAI_NFSROOT/var/log/fai
+
+# pick a context number
+CTX=1000
+while [ -d /proc/virtual/$CTX ]
+do
+ CTX=`expr $CTX + 1`
+done
+
+# suppresses color logo, as it does not leave the terminal in a nice
+# state.
+console=dummy
+
+# set up interfaces, so that the vserver can be built with restricted
+# network access.
+echo "SETUP_INTERFACES is $SETUP_INTERFACES"
+for i in "${SETUP_INTERFACES[@]}"
+do
+ eval "`perl -le '$ARGV[0] =~ m{^(?:([^:]*):)?((?:\d+\.){3}\d+)(?:/(\d+))?$} && do { print for (\"iface=$1\", \"addr=$2\", \"prefix=$3\") }' $i`"
+ echo "iface: $iface, $addr, $prefix"
+ if [ -n "$iface" -a -n "$prefix" ]
+ then
+ ip addr del $addr/$prefix dev $iface 2>/dev/null ||:
+ ip addr add $addr/$prefix dev $iface
+ IFSPEC="$IFSPEC --ip $addr"
+ AFTER="${AFTER}ip addr del $addr/$prefix dev $iface
+ "
+ else
+ echo "WARNING: FAI build method can't understand ifspec '$i'"
+ fi
+done
+
+echo "IFSPEC is $IFSPEC"
+if [ -n "$IFSPEC" ]
+then
+ chbind="/usr/sbin/chbind $IFSPEC"
+fi
+
+# last chance to abort!
+if [ -z "$AUTO" ]
+then
+ echo -n "Press ENTER to begin, or Ctrl+C to cancel: "
+ read junk
+fi
+
+rm -f /tmp/go 2>/dev/null ||:
+mkfifo /tmp/go
+
+(
+read junk < /tmp/go
+vattribute --set --xid $CTX --secure --ccap secure_mount
+[ -z "$SETUP_HOSTNAME" ] && SETUP_HOSTNAME="vs$CTX"
+vuname -s --xid $CTX -t nodename=$SETUP_HOSTNAME
+) &
+
+killprocs() {
+if [ -e /proc/virtual/$CTX ]
+then
+echo "Killing stray processes in context $CTX:"
+vps ax | grep -w $CTX | perl -nle 'm{^\s*(\d+)\s+(\d+)\s+(.*)} && ('$CTX') && ('$CTX' == $2) && do { print "$1 $3"; kill 15, $1 or warn "Error sending signal: $!" }'
+sleep 2;
+vps ax | grep -w $CTX | perl -nle 'm{^\s*(\d+)\s+(\d+)\s+(.*)} && ('$CTX') && ('$CTX' == $2) && do { print "$1 $3"; kill 9, $1 or warn "Error sending signal: $!" }'
+fi
+set -x
+eval $AFTER
+}
+
+trap killprocs INT EXIT
+
+rwpaths="/var/lock /var/log /dev /var/run /etc/sysconfig"
+if [ -d "$FAI_NFSROOT/etc/network/run" ]
+then
+ rwpaths="$rwpaths /etc/network/run"
+fi
+
+export VDIR ROOTDIR FAI_VSERVER FAI_DIR FAI_NFSROOT FAI_ROOT console
+
+if [ -z "$AUTO" ]
+then
+ FINAL_SHELL="exec /bin/sh -i"
+fi
+
+vnamespace -n -- sh $SH_DEBUG -c "
+ mount -n -o ro --bind $FAI_NFSROOT /mnt &&
+ mount -n -t tmpfs -o size=64m,mode=1777 vm /mnt/tmp &&
+ mkdir /mnt/tmp/target &&
+ mount -n --bind $VDIR /mnt/tmp/target &&
+ (mkdir /mnt/tmp/target/proc 2>/dev/null;
+ mount -n -t proc proc /mnt/tmp/target/proc ) &&
+ for x in $rwpaths
+ do
+ /mnt/usr/lib/fai/mkrw -n /mnt\$x
+ done &&
+ mount -n -o ro --bind $FAI_DIR /mnt/fai &&
+ mount -n -t proc proc /mnt/proc &&
+ $chbind chcontext --secure --xid $CTX /bin/sh -c '
+ echo "ok" > /tmp/go
+ sleep 1
+ chroot /mnt /bin/sh -c \
+ \"/bin/sh $SH_DEBUG /etc/init.d/rcS -N vschild_build; $FINAL_SHELL\"'"
+
+base.setSuccess

_______________________________________________
Vserver mailing list
Vserver@list.linux-vserver.org
http://list.linux-vserver.org/mailman/listinfo/vserver
Received on Wed Sep 27 00:33:03 2006

[Next/Previous Months] [Main vserver Project Homepage] [Howto Subscribe/Unsubscribe] [Paul Sladen's vserver stuff]
Generated on Wed 27 Sep 2006 - 00:33:13 BST by hypermail 2.1.8