Unverified Commit 22e2f763 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

Make preallocation configurable

Make preallocation configurable
parents 7a6a847a ab37d366
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+40 −25
Original line number Diff line number Diff line
@@ -29,20 +29,27 @@ if [ -f "${DATA}" ]; then

    echo "INFO: Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.."

    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
        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
  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

  # Create an empty file

  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 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

  # 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
      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="\
+2 −2
Original line number Diff line number Diff line
@@ -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"
+2 −0
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -eu

# Docker environment variabeles

: ${VM_NET_TAP:=''}
: ${VM_NET_IP:='20.20.20.21'}
: ${VM_NET_HOST:='VirtualDSM'}
+1 −2
Original line number Diff line number Diff line
@@ -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

Loading