From c6f94ea59fbf5390c755312b50dadaa98a8f6076 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 17:42:59 +0200 Subject: [PATCH 01/14] Docker environment vars --- run/run.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/run/run.sh b/run/run.sh index 4921d5b..27a6842 100755 --- a/run/run.sh +++ b/run/run.sh @@ -1,6 +1,11 @@ #!/usr/bin/env bash set -eu +# Docker environment vars + +: ${URL:=''}. # URL of PAT file +: ${ALLOCATE:='Y'} # Preallocate diskspace + echo "Starting Virtual DSM for Docker v${VERSION}..." STORAGE="/storage" From b897eb22a4c3594ae024a0fe9ebfbfa615c07a95 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 17:46:58 +0200 Subject: [PATCH 02/14] Docker environment vars --- run/run.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/run/run.sh b/run/run.sh index 27a6842..e1adf9c 100755 --- a/run/run.sh +++ b/run/run.sh @@ -3,8 +3,11 @@ set -eu # Docker environment vars -: ${URL:=''}. # URL of PAT file -: ${ALLOCATE:='Y'} # Preallocate diskspace +: ${URL:=''}. # URL of PAT file +: ${ALLOCATE:='Y'} # Preallocate diskspace +: ${CPU_CORES:='1'} # vCPU count +: ${DISK_SIZE:='16G'} # Initial disk size +: ${RAM_SIZE:='512M'} # Amount of RAM echo "Starting Virtual DSM for Docker v${VERSION}..." From e3b2e749aefed48eb5471687f36a049085b983e3 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 17:47:41 +0200 Subject: [PATCH 03/14] Docker environment vars --- run/network.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run/network.sh b/run/network.sh index 708f513..01d3a80 100644 --- a/run/network.sh +++ b/run/network.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -eu +# Docker environment vars + : ${VM_NET_TAP:=''} : ${VM_NET_IP:='20.20.20.21'} : ${VM_NET_HOST:='VirtualDSM'} From 64aefc2a3da61c77ce8aa3bbc97d179ac65ce582 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 17:49:24 +0200 Subject: [PATCH 04/14] Docker environment variabeles --- run/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/run.sh b/run/run.sh index e1adf9c..076e4f8 100755 --- a/run/run.sh +++ b/run/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eu -# Docker environment vars +# Docker environment variabeles : ${URL:=''}. # URL of PAT file : ${ALLOCATE:='Y'} # Preallocate diskspace From 5a679550dafb9818c9b9ed47df6baa7bc4cdf6bd Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 17:49:41 +0200 Subject: [PATCH 05/14] Docker environment variabeles --- run/network.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/network.sh b/run/network.sh index 01d3a80..2d76935 100644 --- a/run/network.sh +++ b/run/network.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eu -# Docker environment vars +# Docker environment variabeles : ${VM_NET_TAP:=''} : ${VM_NET_IP:='20.20.20.21'} From eaf7a3b89c5b0824864fde0c703fc54e9b3abb8f Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 17:59:19 +0200 Subject: [PATCH 06/14] Make allocation method configurable --- run/disk.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/run/disk.sh b/run/disk.sh index 1ee70af..e5ccabe 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -65,9 +65,18 @@ if [ ! -f "${DATA}" ]; then fi # Create an empty file - if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then - rm -f "${DATA}" - echo "ERROR: Could not allocate file for virtual disk." && exit 87 + + if [ "$ALLOCATE" != "Y" ]; then + + truncate -s "${DATA_SIZE}" "${DATA}" + + else + + if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then + rm -f "${DATA}" + echo "ERROR: Could not allocate file for virtual disk." && exit 87 + fi + fi # Check if file exists @@ -80,12 +89,11 @@ if [ ! -f "${DATA}" ]; then fi -AGENT_VERSION=1 AGENT="${STORAGE}/${BASE}.agent" -[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") +[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") || AGENT_VERSION=1 if ((AGENT_VERSION < 5)); then - echo "INFO: The installed VirtualDSM Agent is an outdated version, please upgrade it." + echo "INFO: The installed VirtualDSM Agent v${AGENT_VERSION} is an outdated version, please upgrade it." fi KVM_DISK_OPTS="\ From a18cdf17d458c38b6907985e33e277fedfe2b4f5 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 18:05:52 +0200 Subject: [PATCH 07/14] Make allocation method configurable --- run/disk.sh | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/run/disk.sh b/run/disk.sh index e5ccabe..4c4c682 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -28,20 +28,27 @@ if [ -f "${DATA}" ]; then if [ "$DATA_SIZE" -gt "$OLD_SIZE" ]; then echo "INFO: Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.." - - REQ=$((DATA_SIZE-OLD_SIZE)) - - # Check free diskspace - SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1) - - if (( REQ > SPACE )); then - echo "ERROR: Not enough free space to resize virtual disk." && exit 84 - fi - if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then - echo "ERROR: Could not allocate file for virtual disk." && exit 85 + if [ "$ALLOCATE" != "Y" ]; then + + truncate -s "${DATA_SIZE}" "${DATA}"; + + else + + REQ=$((DATA_SIZE-OLD_SIZE)) + + # Check free diskspace + SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1) + + if (( REQ > SPACE )); then + echo "ERROR: Not enough free space to resize virtual disk." && exit 84 + fi + + if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then + echo "ERROR: Could not allocate file for virtual disk." && exit 85 + fi + fi - fi if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then @@ -52,18 +59,10 @@ if [ -f "${DATA}" ]; then mv -f "${DATA}" "${DATA}.bak" fi - fi if [ ! -f "${DATA}" ]; then - # Check free diskspace - SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1) - - if (( DATA_SIZE > SPACE )); then - echo "ERROR: Not enough free space to create virtual disk." && exit 86 - fi - # Create an empty file if [ "$ALLOCATE" != "Y" ]; then @@ -72,6 +71,13 @@ if [ ! -f "${DATA}" ]; then else + # Check free diskspace + SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1) + + if (( DATA_SIZE > SPACE )); then + echo "ERROR: Not enough free space to create virtual disk." && exit 86 + fi + if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then rm -f "${DATA}" echo "ERROR: Could not allocate file for virtual disk." && exit 87 From 05d49ae4347bee996867eb9046cfd991d20d3295 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 18:06:59 +0200 Subject: [PATCH 08/14] Agent --- run/power.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/run/power.sh b/run/power.sh index b49cc8a..7a567db 100644 --- a/run/power.sh +++ b/run/power.sh @@ -42,9 +42,8 @@ _graceful_shutdown(){ # If we cannot shutdown the usual way, fallback to the NMI method - AGENT_VERSION=1 AGENT="${STORAGE}/${BASE}.agent" - [ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") + [ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") || AGENT_VERSION=1 if ((AGENT_VERSION < 2)); then From e29a0f13832b2dfb2f780593a6d4a63e71453a1f Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 18:13:05 +0200 Subject: [PATCH 09/14] Make preallocation configurable --- run/install.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/run/install.sh b/run/install.sh index 1356b3d..8d7eb5d 100644 --- a/run/install.sh +++ b/run/install.sh @@ -108,16 +108,24 @@ echo "Install: Creating partition table..." SYSTEM="$TMP/sys.img" SYSTEM_SIZE="4954537983" -# Check free diskspace -SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) +if [ "$ALLOCATE" != "Y" ]; then -if (( SYSTEM_SIZE > SPACE )); then - echo "ERROR: Not enough free space to create virtual system disk." && exit 87 -fi + truncate -s "${SYSTEM_SIZE}" "${SYSTEM}"; + +else + + # Check free diskspace + SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) + + if (( SYSTEM_SIZE > SPACE )); then + echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87 + fi + + if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then + rm -f "${SYSTEM}" + echo "ERROR: Could not allocate a file for the system disk." && exit 88 + fi -if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then - rm -f "${SYSTEM}" - echo "ERROR: Could not allocate file for virtual system disk." && exit 88 fi PART="$TMP/partition.fdisk" From cbd1c301ee882212a6c902b4e6e46cf9d9c3dc42 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 18:16:41 +0200 Subject: [PATCH 10/14] Allocate --- run/install.sh | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/run/install.sh b/run/install.sh index 8d7eb5d..75e238f 100644 --- a/run/install.sh +++ b/run/install.sh @@ -108,24 +108,16 @@ echo "Install: Creating partition table..." SYSTEM="$TMP/sys.img" SYSTEM_SIZE="4954537983" -if [ "$ALLOCATE" != "Y" ]; then +# Check free diskspace +SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) - truncate -s "${SYSTEM_SIZE}" "${SYSTEM}"; - -else - - # Check free diskspace - SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) - - if (( SYSTEM_SIZE > SPACE )); then - echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87 - fi - - if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then - rm -f "${SYSTEM}" - echo "ERROR: Could not allocate a file for the system disk." && exit 88 - fi +if (( SYSTEM_SIZE > SPACE )); then + echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87 +fi +if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then + rm -f "${SYSTEM}" + echo "ERROR: Could not allocate a file for the system disk." && exit 88 fi PART="$TMP/partition.fdisk" From 249004c84c350e769705a6eee52a530287e491f5 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 18:22:11 +0200 Subject: [PATCH 11/14] Make preallocation configurable --- run/disk.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/run/disk.sh b/run/disk.sh index 4c4c682..6f4c593 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -41,11 +41,11 @@ if [ -f "${DATA}" ]; then SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1) if (( REQ > SPACE )); then - echo "ERROR: Not enough free space to resize virtual disk." && exit 84 + echo "ERROR: Not enough free space to resize virtual disk to ${DISK_SIZE}." && exit 84 fi if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then - echo "ERROR: Could not allocate file for virtual disk." && exit 85 + echo "ERROR: Could not allocate a file for the virtual disk." && exit 85 fi fi @@ -75,7 +75,8 @@ if [ ! -f "${DATA}" ]; then SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1) if (( DATA_SIZE > SPACE )); then - echo "ERROR: Not enough free space to create virtual disk." && exit 86 + echo "ERROR: Not enough free space to create a virtual disk of ${DISK_SIZE}." + echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 86 fi if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then From b5194655d1745cc9c569b7f582ca2044a94cdf56 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 18:25:17 +0200 Subject: [PATCH 12/14] Make preallocation configurable --- run/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/install.sh b/run/install.sh index 75e238f..1bef13d 100644 --- a/run/install.sh +++ b/run/install.sh @@ -112,7 +112,7 @@ SYSTEM_SIZE="4954537983" SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) if (( SYSTEM_SIZE > SPACE )); then - echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87 + echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87 fi if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then From ce0e4f88e2e37e5542b853d1f6845349913e29c4 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 18:26:15 +0200 Subject: [PATCH 13/14] Make preallocation configurable --- run/disk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/disk.sh b/run/disk.sh index 6f4c593..4d7e829 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -81,7 +81,7 @@ if [ ! -f "${DATA}" ]; then if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then rm -f "${DATA}" - echo "ERROR: Could not allocate file for virtual disk." && exit 87 + echo "ERROR: Could not allocate a file for the virtual disk." && exit 87 fi fi From e4f34db022fb7185ff7324dc0bcd249ddfb96668 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Apr 2023 18:29:50 +0200 Subject: [PATCH 14/14] Make preallocation configurable --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 627a47e..5c28e1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,6 +48,7 @@ EXPOSE 5000 EXPOSE 5001 ENV URL "" +ENV ALLOCATE Y ENV CPU_CORES 1 ENV DISK_SIZE 16G ENV RAM_SIZE 512M