From c58f94d5370e08c089d2c557bbd84d3486ffb599 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sat, 30 Jun 2018 20:01:23 +0000 Subject: [PATCH] Use random port --- appvm.sh | 6 +++++- qemu/qemu.template | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/appvm.sh b/appvm.sh index fb7dc89..63bd431 100755 --- a/appvm.sh +++ b/appvm.sh @@ -10,7 +10,11 @@ if [[ "$1" == "build" && "$2" != "" ]]; then sed "s;NIX_SYSTEM_PLACEHOLDER;${NIX_SYSTEM};" qemu/qemu.template > bin/appvm.${2} sed -i "s;NAME_PLACEHOLDER;${2};" bin/appvm.${2} sed -i "s;NIX_DISK_IMAGE_PLACEHOLDER;${APPVM_PATH}/qemu/qcow2/${2}.qcow2;" bin/appvm.${2} - chmod +x bin/appvm.${2} + RANDOM_PORT=$(/usr/bin/python -c 'import random; print(random.randint(1024,65535))') + # TODO Check for port collisions + sed -i "s;PORT_PLACEHOLDER;${RANDOM_PORT};" bin/appvm.${2} + echo -e "#!/bin/bash\nremote-viewer -f spice://127.200.0.1:${RANDOM_PORT}" > bin/appgui.${2} + chmod +x bin/app{vm,gui}.${2} unlink result else echo "Usage: $0 build APPLICATION" diff --git a/qemu/qemu.template b/qemu/qemu.template index a9fc0d8..772e6af 100644 --- a/qemu/qemu.template +++ b/qemu/qemu.template @@ -26,7 +26,7 @@ qemu-system-x86_64 -enable-kvm \ -smp 1 \ -device virtio-rng-pci \ -net nic,netdev=user.0,model=virtio -netdev user,id=user.0${QEMU_NET_OPTS:+,$QEMU_NET_OPTS} \ - -spice port=5900,addr=127.0.0.1,disable-ticketing,image-compression=off,seamless-migration=on \ + -spice port=PORT_PLACEHOLDER,addr=127.200.0.1,disable-ticketing,image-compression=off,seamless-migration=on \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -virtfs local,path=/nix/store,security_model=none,mount_tag=store,readonly \ -virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \