diff --git a/run/check.sh b/run/check.sh index a306e4d1..acfc33b8 100644 --- a/run/check.sh +++ b/run/check.sh @@ -3,19 +3,16 @@ set -u [ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0 -# Retrieve IP from guest for Docker healthcheck +# Retrieve IP from guest VM for Docker healthcheck RESPONSE=$(curl -s -m 6 -S http://127.0.0.1:2210/read?command=10 2>&1) if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then - echo "Failed to connect to guest: $RESPONSE" - exit 1 + echo "Failed to connect to guest: $RESPONSE" && exit 1 fi # Retrieve the HTTP port number - if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then - echo "Failed to parse response from guest: $RESPONSE" - exit 1 + echo "Failed to parse response from guest: $RESPONSE" && exit 1 fi rest=${RESPONSE#*http_port} @@ -23,16 +20,11 @@ rest=${rest#*:} rest=${rest%%,*} PORT=${rest%%\"*} -if [ -z "${PORT}" ]; then - echo "Guest has not set a portnumber yet.." - exit 1 -fi +[ -z "${PORT}" ] && echo "Guest has not set a portnumber yet.." && exit 1 # Retrieve the IP address - if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then - echo "Failed to parse response from guest: $RESPONSE" - exit 1 + echo "Failed to parse response from guest: $RESPONSE" && exit 1 fi rest=${RESPONSE#*eth0} @@ -41,15 +33,17 @@ rest=${rest#*:} rest=${rest#*\"} IP=${rest%%\"*} -if [ -z "${IP}" ]; then - echo "Guest has not received an IP yet.." - exit 1 -fi +[ -z "${IP}" ] && echo "Guest has not received an IP yet.." && exit 1 if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then echo "Failed to reach ${IP}:${PORT}" exit 1 fi -echo "Healthcheck OK ($IP)" +if [[ "$IP" == "20.20"* ]]; then + echo "Healthcheck OK" +else + echo "Healthcheck OK ( $IP )" +fi + exit 0 diff --git a/run/disk.sh b/run/disk.sh index 777d4e63..55e373fd 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -3,7 +3,7 @@ set -Eeuo pipefail # Docker environment variables -: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' +: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' : ${DISK_CACHE:='none'} # Caching mode, can be set to 'writeback' for better performance : ${DISK_DISCARD:='on'} # Controls whether unmap (TRIM) commands are passed to the host. : ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD diff --git a/run/network.sh b/run/network.sh index f405a139..8056dbf5 100644 --- a/run/network.sh +++ b/run/network.sh @@ -22,49 +22,23 @@ set -Eeuo pipefail configureDHCP() { - VM_NET_VLAN="${VM_NET_TAP}_vlan" - GATEWAY=$(ip r | grep default | awk '{print $3}') - NETWORK=$(ip -o route | grep "${VM_NET_DEV}" | grep -v default | awk '{print $1}') - IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) - - [[ "${DEBUG}" == [Yy1]* ]] && set -x - - # Create a macvlan network to allow for communication between the host and the VM guest - { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || : - - if (( rc != 0 )); then - error "Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," - error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15 - fi - - ip address add "${IP}" dev "${VM_NET_VLAN}" - ip link set dev "${VM_NET_VLAN}" up - - ip route flush dev "${VM_NET_VLAN}" - ip route del "${NETWORK}" dev "${VM_NET_DEV}" - ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0 - # Create a macvtap network for the VM guest - { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || : + { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || : + if (( rc != 0 )); then - error "Capability NET_ADMIN has not been set most likely. Please add the " - error "following docker setting to your container: --cap-add NET_ADMIN" && exit 16 + error "Cannot create macvtap interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," + error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 16 fi ip link set "${VM_NET_TAP}" up - { set +x; } 2>/dev/null - TAP_NR=$(/dev/null + + [[ "${DEBUG}" == [Yy1]* ]] && echo } # ###################################### @@ -236,6 +213,4 @@ fi NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0" -[[ "${DEBUG}" == [Yy1]* ]] && echo && info "Finished network setup.." && echo - return 0 diff --git a/run/power.sh b/run/power.sh index 23040a3e..30486f71 100644 --- a/run/power.sh +++ b/run/power.sh @@ -78,7 +78,7 @@ _graceful_shutdown() { done - echo && info "Quitting..." + echo && echo "❯ Quitting..." echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true return diff --git a/run/run.sh b/run/run.sh index a4ba5e49..dbe98c04 100755 --- a/run/run.sh +++ b/run/run.sh @@ -10,11 +10,11 @@ set -Eeuo pipefail : ${DISK_SIZE:='16G'} # Initial data disk size : ${RAM_SIZE:='512M'} # Maximum RAM amount +echo "❯ Starting Virtual DSM for Docker v${VERSION}..." + info () { echo -e "\E[1;34m❯ \E[1;36m$1\E[0m" ; } error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; } - -echo "❯ Starting Virtual DSM for Docker v${VERSION}..." -trap 'error "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR +trap 'error "Status $? while: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR [ ! -f "/run/run.sh" ] && error "Script must run inside Docker container!" && exit 11 [ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12 @@ -61,7 +61,7 @@ else fi if [ -n "${KVM_ERR}" ]; then - error "KVM acceleration not detected ${KVM_ERR}, please enable it." + error "KVM acceleration not detected ${KVM_ERR}, see the FAQ about this." [[ "${DEBUG}" == [Yy1]* ]] && exit 88 else KVM_OPTS=",accel=kvm -enable-kvm -cpu host" diff --git a/run/server.sh b/run/server.sh index 37cd61b9..045d3d50 100644 --- a/run/server.sh +++ b/run/server.sh @@ -13,7 +13,7 @@ trap 'stop' EXIT SIGINT SIGTERM SIGHUP html() { - local h="VirtualDSM" + local h="VirtualDSM" h="${h} " h="${h}

$1

"