From f0f065c84985ef9e3e34b7009ed2355518075d0a Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 23 Oct 2012 15:26:08 +0200 Subject: [PATCH] utility to create debian vservers --- scripts/create-vm-debian.sh | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 scripts/create-vm-debian.sh diff --git a/scripts/create-vm-debian.sh b/scripts/create-vm-debian.sh new file mode 100755 index 0000000..a26c4e7 --- /dev/null +++ b/scripts/create-vm-debian.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# WARNING: looks like specifying another arch/preso won't work + +COMMAND=$(basename $0) +DIRNAME=$(dirname $0) + +#BUILD="${HOME}/git-build" +DOMAIN=pl.sophia.inria.fr + +DEFAULT_DISTRO=wheezy +DEFAULT_PERSO=linux64 + +INTERACTIVE= +DISTRO=$DEFAULT_DISTRO +PERSO=$DEFAULT_PERSO +function usage () { + message="$@" + echo "usage : $COMMAND [-i] [-f distro] [-p perso] hostname" + echo " default distro is $DEFAULT_DISTRO" + echo " default perso is $DEFAULT_PERSO" + [ -n "$message" ] && echo $message + exit 1 +} + +while getopts "f:p:ih" flag; do + case $flag in + f) DISTRO=$OPTARG;; + p) PERSO=$OPTARG;; + i) INTERACTIVE=true ;; + ?|h) usage "" ;; + esac +done +shift $((OPTIND-1)) +[[ -z "$@" ]] && usage "no hostname provided" +HOSTNAME="$1" ; shift +[[ -n "$@" ]] && usage "extra arguments" "$@" "(hostname=$HOSTNAME)" + + +#[ -d "$BUILD" ] || usage "Could not find directory $BUILD" + +[ -d /vservers/$HOSTNAME ] && usage "vserver $HOSTNAME already exists in /vservers" +# debian distros not found there - skip that +#[ -d /etc/vservers/.distributions/$DISTRO ] || usage "distro $DISTRO not known in /etc/vservers/.distributions/" +rpm -q debootstrap >& /dev/null || usage "You need to first run 'yum install debootstrap'" + +fqdn=$HOSTNAME.$DOMAIN +## compute IP +host $fqdn | grep -q 'has address' || usage "hostname $fqdn not known to DNS" +ip=$(host $fqdn | grep 'has address' | awk '{print $4}') + +#cd $BUILD +#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" + +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} " + +if [ -n "$INTERACTIVE" ] ; then + echo -n "Run $command OK ? " + read answer ; case $answer in [nN]*) exit 1 ;; esac +fi + +$command + +### post processing for starting up +for dir in run lock; do + [ -d /vservers/${HOSTNAME}/var/$dir ] || mkdir /vservers/${HOSTNAME}/var/$dir +done + +vserver ${HOSTNAME} start -- 2.47.0