Commit 0cd1ddf0 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Cache DSM info (#378)

* feat: Cache location

* feat: Cache location

* feat: Add support URL

* feat: Cache location

* fix: Remove files

* feat: Reset filesystem

* fix: Exit when PID is missing

* fix: Counter file

* fix: Check flags

* docs: Readme

* feat: Cleanup files

* fix: Check flags

* fix: Check flags

* fix: Initialization

* fix: Initalization

* fix: Initialization

* fix: Cleanup temp

* fix: Initialize system

* feat: Config system

* feat: Configure system

* fix: Variables

* fix: Variables

* fix: Error handling

* style: Comments

* fix: Returnvalue

* fix: Returnvalue

* fix: Returnvalue

* fix: Returnvalue

* fix: Returnvalue

* docs: Multi-disk support

* feat: Use cached location

* fix: Swap order
parent 98245a1e
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ Virtual DSM in a docker container.
 - Multi-platform
 - KVM acceleration
 - GPU passthrough
 - Graceful shutdowns
 - Upgrades supported
 
## Usage
@@ -86,6 +85,32 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti

    Keep in mind that this will not affect any of your existing disks, it only applies to newly created disks.
    
  * ### How do I add multiple disks?

    To mount extra volumes, modify your compose file like this:
    
    ```yaml
    environment:
      DISK2_SIZE: "32G"
      DISK3_SIZE: "64G"
    volumes:
      - /home/example2:/storage2
      - /home/example3:/storage3
    ```

    Additionally, it's also possible to passthrough raw disk devices like this:

    ```yaml
    environment:
      DEVICE2: "/dev/vdc1"
      DEVICE3: "/dev/vdc2"
    devices:
      - /dev/vdc1
      - /dev/vdc2
    ```    

    Please beware that any pre-existing partitions and data on those devices will be wiped.

  * ### How do I increase the amount of CPU or RAM?

    By default, a single core and 512 MB of RAM are allocated to the container. To increase this, add the following environment variables:
+40 −29
Original line number Diff line number Diff line
@@ -2,7 +2,11 @@
set -u

[ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0
[ -f "/run/qemu.counter" ] && echo "QEMU is shutting down.." && exit 1
[ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1

file="/run/dsm.url"

if [ ! -f  "$file" ]; then

  # Retrieve IP from guest VM for Docker healthcheck
  RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1)
@@ -36,15 +40,22 @@ IP=${rest%%\"*}

  [ -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}"
  echo "${IP}:${PORT}" > $file

fi

LOCATION=$(cat "$file")

if ! curl -m 20 -ILfSs "http://${LOCATION}/" > /dev/null; then
  rm -f $file
  echo "Failed to reach http://${LOCATION}"
  exit 1
fi

if [[ "$IP" == "20.20"* ]]; then
if [[ "$LOCATION" == "20.20"* ]]; then
  echo "Healthcheck OK"
else
  echo "Healthcheck OK ( $IP )"
  echo "Healthcheck OK ( ${LOCATION%:*} )"
fi

exit 0

run/config.sh

0 → 100644
+40 −0
Original line number Diff line number Diff line
#!/bin/bash
set -Eeuo pipefail

KVM_ERR=""
KVM_OPTS=""

if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then
  if ! grep -q -e vmx -e svm /proc/cpuinfo; then
    KVM_ERR="(vmx/svm disabled)"
  fi
else
  [ -e /dev/kvm ] && KVM_ERR="(no write access)" || KVM_ERR="(device file missing)"
fi

if [ -n "${KVM_ERR}" ]; then
  if [ "$ARCH" == "amd64" ]; then
    error "KVM acceleration not detected ${KVM_ERR}, see the FAQ about this."
    [[ "${DEBUG}" != [Yy1]* ]] && exit 88
  fi
else
  KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
fi

DEF_OPTS="-nographic -nodefaults -boot strict=on -display none"
RAM_OPTS=$(echo "-m ${RAM_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
CPU_OPTS="-smp ${CPU_CORES},sockets=1,dies=1,cores=${CPU_CORES},threads=1"
MAC_OPTS="-machine type=q35,usb=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
EXTRA_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
EXTRA_OPTS="$EXTRA_OPTS -object rng-random,id=objrng0,filename=/dev/urandom"
EXTRA_OPTS="$EXTRA_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"

if [[ "${GPU}" == [Yy1]* ]] && [[ "$ARCH" == "amd64" ]]; then
  DEF_OPTS="-nodefaults -boot strict=on -display egl-headless,rendernode=/dev/dri/renderD128"
  DEF_OPTS="${DEF_OPTS} -device virtio-vga,id=video0,max_outputs=1,bus=pcie.0,addr=0x1"
fi

ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${MAC_OPTS} ${MON_OPTS} ${SERIAL_OPTS} ${NET_OPTS} ${DISK_OPTS} ${EXTRA_OPTS} ${ARGUMENTS}"
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')

return 0
+2 −0
Original line number Diff line number Diff line
@@ -237,3 +237,5 @@ if [ -n "${DEVICE3}" ]; then
    -device scsi-hd,bus=hw-userdata6.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata6,id=userdata6,rotation_rate=${DISK_ROTATION},bootindex=8"

fi

return 0
+6 −3
Original line number Diff line number Diff line
#!/bin/bash
set -Eeuo pipefail

if [[ "${GPU}" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then
  return 0
fi

[ ! -d /dev/dri ] && mkdir -m 755 /dev/dri

if [ ! -c /dev/dri/card0 ]; then
@@ -14,9 +18,6 @@ fi
chmod 666 /dev/dri/card0
chmod 666 /dev/dri/renderD128

DEF_OPTS="-nodefaults -boot strict=on -display egl-headless,rendernode=/dev/dri/renderD128"
DEF_OPTS="${DEF_OPTS} -device virtio-vga,id=video0,max_outputs=1,bus=pcie.0,addr=0x1"

if ! apt-mark showinstall | grep -q "xserver-xorg-video-intel"; then

  info "Installing Intel GPU drivers..."
@@ -40,3 +41,5 @@ if ! apt-mark showinstall | grep -q "qemu-system-modules-opengl"; then
  apt-get -qq --no-install-recommends -y install qemu-system-modules-opengl > /dev/null

fi

return 0
Loading