debian builds on warhol
[infrastructure.git] / scripts / create-vm-debian.sh
index ffaebc7..33eebc2 100755 (executable)
@@ -53,15 +53,22 @@ ip=$(host $fqdn | grep 'has address' | awk '{print $4}')
 #git pull
 #cd -
 
-# single_ip needs to be turned off, vtest-init-vserver now takes care of that
-#command="$BUILD/vtest-init-vserver.sh -p $PERSO -f $DISTRO $HOSTNAME none -- --interface eth0:$ip --hostname $fqdn"
+# single_ip needs to be turned off, vtest-initvm now takes care of that
+#command="$BUILD/vtest-initvm.sh -p $PERSO -f $DISTRO $HOSTNAME none -- --interface eth0:$ip --hostname $fqdn"
 
 case $PERSO in
     linux32) arch=i386;;
     linux64) arch=amd64;;
 esac
 
-command="$PERSO vserver ${HOSTNAME} build -m debootstrap --interface eth0:${ip}/21 --hostname ${fqdn} -- -d ${DISTRO} -m http://ftp2.fr.debian.org/debian/ -- --verbose --arch=${arch} "
+case $DISTRO in
+    squeeze|wheezy) DEBMIRROR=http://ftp2.fr.debian.org/debian/ ;;
+# from the vserver man page DEBMIRROR=http://us.archive.ubuntu.com/ubuntu/ ;;
+    oneiric|precise|quantal) DEBMIRROR=http://mir1.ovh.net/ubuntu/ubuntu/ ;;
+    *) echo unknown distro $DISTRO; exit 1;;
+esac
+
+command="$PERSO vserver ${HOSTNAME} build -m debootstrap --interface eth0:${ip}/21 --hostname ${fqdn} -- -d ${DISTRO} -m ${DEBMIRROR} -- --verbose --arch=${arch} "
 
 if [ -n "$INTERACTIVE" ] ; then
     echo -n "Run $command OK ? "
@@ -70,12 +77,18 @@ fi
 
 $command
 
-### it looks like this is done too early or something
-sleep 5
-# with wheezy at least, we need to manually create these 2 directories when trying to vserver start for the first time..
-### post processing for starting up
-for dir in run lock; do
-    [ -d /vservers/${HOSTNAME}/var/$dir ] || mkdir /vservers/${HOSTNAME}/var/$dir
-done
+## stolen from vbuild-util-vserver (might be that we can actually use that one as-is...)
+# turns out that with wheezy at least, at this point we're getting 
+# /vservers/<vs>/var/run -> /run
+# /vservers/<vs>/var/lock -> /run/lock
+# trying to fix this with relative links does not appear to work fine
+# when trying to vserver start we're then getting
+# + exec /usr/sbin/vspace --mount --fs --new -- /usr/sbin/vserver ----nonamespace debuild09 start
+# fakerunlevel: open("/var/run/utmp"): No such file or directory
+# so instead we bluntly create empty dirs and hope for the best
+[ -h /vservers/${HOSTNAME}/var/run ] && [ ! -d /vservers/${HOSTNAME}/var/run ] && \
+    { rm -f /vservers/${HOSTNAME}/var/run ; mkdir /vservers/${HOSTNAME}/var/run ; }
+[ -h /vservers/${HOSTNAME}/var/lock ] && [ ! -d /vservers/${HOSTNAME}/var/lock ] && \
+    { rm -f /vservers/${HOSTNAME}/var/lock ; mkdir /vservers/${HOSTNAME}/var/lock ; }
 
 vserver ${HOSTNAME} start