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 diff --git a/run/disk.sh b/run/disk.sh index 1ee70af..4d7e829 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 to ${DISK_SIZE}." && exit 84 + fi + + if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then + echo "ERROR: Could not allocate a file for the virtual disk." && exit 85 + fi + fi - fi if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then @@ -52,22 +59,31 @@ 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 ! 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 + + # 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 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 + rm -f "${DATA}" + echo "ERROR: Could not allocate a file for the virtual disk." && exit 87 + fi + fi # Check if file exists @@ -80,12 +96,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="\ diff --git a/run/install.sh b/run/install.sh index 1356b3d..1bef13d 100644 --- a/run/install.sh +++ b/run/install.sh @@ -112,12 +112,12 @@ 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 virtual 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 rm -f "${SYSTEM}" - echo "ERROR: Could not allocate file for virtual system disk." && exit 88 + echo "ERROR: Could not allocate a file for the system disk." && exit 88 fi PART="$TMP/partition.fdisk" diff --git a/run/network.sh b/run/network.sh index 708f513..2d76935 100644 --- a/run/network.sh +++ b/run/network.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -eu +# Docker environment variabeles + : ${VM_NET_TAP:=''} : ${VM_NET_IP:='20.20.20.21'} : ${VM_NET_HOST:='VirtualDSM'} 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 diff --git a/run/run.sh b/run/run.sh index 4921d5b..076e4f8 100755 --- a/run/run.sh +++ b/run/run.sh @@ -1,6 +1,14 @@ #!/usr/bin/env bash set -eu +# Docker environment variabeles + +: ${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}..." STORAGE="/storage"