7 # this whole lot won't work well with ubuntu containers any longer
8 # tried with webprivacy on bionic, and
9 # (*) the initial populating phase somehow spawned a question screen
10 # something about asking questions during upgrades..
11 # so I had to turn off the redirection into ~/machines/<container>.log
12 # (*) more badly, the resulting container does not start its network upon boot
13 # everything is in place and it could be started manually
14 # like for the record e.g.
15 # ip link set dev eth0 up
16 # ip address add 138.96.119.13/21 dev eth0
17 # ip route add default dev eth0 via 138.96.112.250
19 # trying to solve that last issue by apt-get install'ing network-manager
20 # (which was missing indeed) was not enough
21 # a bit more work seems to be needed if that became needed
23 BUILD="${HOME}/git-build"
27 [ -d $LOGS ] || { echo "Creating logs dir $LOGS" ; mkdir -p $LOGS; }
29 DOMAIN=pl.sophia.inria.fr
37 echo "usage : $COMMAND [-c] [-f distro] [-i image] [ -m memory ] [ -n hostname ] [-s] container"
38 echo " -c : confirm, will show the command and prompt for confirmation "
39 echo " -f : set distro, default is $DEFAULT_DISTRO"
40 echo " -i : if specified, image is rsynced into /vservers"
41 echo " warning: we cannot use an image already in /vservers..."
42 echo " -m : memory size in Mb - default is $DEFAULT_MEMORY"
43 echo " -n : specify hostname if different from container"
44 echo " -s : do not start VM"
45 echo " container : used for /vservers/foo as well as the lxc/libvirt name"
47 echo " create-vm.sh sandbox"
48 echo " Builds a brand new $DEFAULT_DISTRO 64bits VM named sandbox with hostname sandbox.pl.sophia.inria.fr"
49 echo " create-vm.sh -i /vservers/migrating/testmaster -n testmaster testmaster.f14"
50 echo " Create a container named testmaster.f14 from the specified image with hostname testmaster.pl.sophia.inria.fr"
51 [ -n "$message" ] && echo $message
55 # using HOSTNAME won't work as this is already set in environment
56 while getopts "cf:i:m:n:sh" flag; do
62 n) VM_HOSTNAME=$OPTARG ;;
63 s) DO_NOT_START_VM=true ;;
69 [[ -z "$@" ]] && usage "no hostname provided"
70 container="$1" ; shift
71 [[ -n "$@" ]] && usage "extra arguments" "$@" "(container=$container)"
74 [ -d "$BUILD" ] || usage "Could not find directory $BUILD"
75 [ -d /vservers/$container ] && usage "container $container already exists in /vservers"
77 echo "Updating $BUILD"
82 # compute all vars from args
83 [ -z "$DISTRO" ] && DISTRO="$DEFAULT_DISTRO"
84 [ -z "$MEMORY" ] && MEMORY="$DEFAULT_MEMORY"
85 [ -z "$VM_HOSTNAME" ] && VM_HOSTNAME="$container"
86 fqdn=$VM_HOSTNAME.$DOMAIN
88 # prepare initvm command
89 initvm="$BUILD/lbuild-initvm.sh"
90 [ -z "$IMAGE" ] && initvm="$initvm -f $DISTRO" || initvm="$initvm -i $IMAGE"
91 initvm="$initvm -n $fqdn"
92 # always use fedora repos
94 [ -n "$DO_NOT_START_VM" ] && initvm="$initvm -s"
95 [ -n "$MEMORY" ] && initvm="$initvm -m $MEMORY"
96 initvm="$initvm $container"
98 if [ -n "$CONFIRM" ] ; then
99 echo -n "Run $initvm OK ? "
100 read answer ; case $answer in [nN]*) exit 1 ;; esac
103 echo "Running $initvm"
104 echo "Storing output in $LOGS/$container.log"
105 $initvm >& $LOGS/$container.log