Unverified Commit 86297c4d authored by Kroese's avatar Kroese Committed by GitHub
Browse files

DHCP fixes

DHCP fixes
parents 8462ec15 456d40bc
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ RUN apt-get update && apt-get -y upgrade && \
	net-tools \
	btrfs-progs \
	ca-certificates \
	isc-dhcp-client \
	netcat-openbsd \
	qemu-system-x86 \
    && apt-get clean
@@ -66,6 +65,6 @@ LABEL org.opencontainers.image.version=${VERSION_ARG}
LABEL org.opencontainers.image.source=https://github.com/kroese/virtual-dsm/
LABEL org.opencontainers.image.url=https://hub.docker.com/r/kroese/virtual-dsm/

HEALTHCHECK --interval=30s --retries=1 CMD /run/check.sh
HEALTHCHECK --interval=30s --retries=3 CMD /run/check.sh

ENTRYPOINT ["/run/run.sh"]
+7 −7
Original line number Diff line number Diff line
@@ -3,16 +3,16 @@ set -u

# Docker Healthcheck

PORT=5000
FILE="/var/dsm.ip"
: ${DHCP:='N'}

if [ ! -f "${FILE}" ]; then
  echo "IP not assigned"
  exit 1
if [ "$DHCP" = "Y" ]; then
  PORT=5555
  IP="127.0.0.1"
else
  PORT=5000
  IP="20.20.20.21"
fi

IP=$(cat "${FILE}")

if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then
  echo "Failed to reach ${IP}:${PORT}"
  exit 1
+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ set -eu
HTML="Please wait while Virtual DSM is installing...<script>\
        setTimeout(() => { document.location.reload(); }, 9999);</script>"

pkill -f server.sh || true
/run/server.sh 80 "${HTML}" > /dev/null &
/run/server.sh 5000 "${HTML}" > /dev/null &

# Download the required files from the Synology website
+12 −22
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ set -eu

configureDHCP() {

  VM_NET_VLAN="vlan"
  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/)
@@ -54,18 +54,6 @@ configureDHCP() {
  ip address flush "${VM_NET_DEV}"
  ip address flush "${VM_NET_TAP}"

  echo "INFO: Acquiring an IP address via DHCP using MAC address ${VM_NET_MAC}..."

  DHCP_IP=$(dhclient -v "${VM_NET_TAP}" 2>&1 | grep ^bound | cut -d' ' -f3)

  if [[ "${DHCP_IP}" == [0-9.]* ]]; then
    echo "INFO: Successfully acquired IP ${DHCP_IP} from the DHCP server..."
  else
    echo "ERROR: Cannot acquire an IP address from the DHCP server" && exit 17
  fi

  ip address flush "${VM_NET_TAP}"

  { set +x; } 2>/dev/null

  TAP_NR=$(</sys/class/net/"${VM_NET_TAP}"/ifindex)
@@ -105,9 +93,6 @@ configureDHCP() {
    echo "docker setting to your container: --device=/dev/vhost-net" && exit 22
  fi

  # Store IP for Docker healthcheck
  echo "${DHCP_IP}" > "/var/dsm.ip"

  NET_OPTS="-netdev tap,id=hostnet0,vhost=on,vhostfd=40,fd=30"
}

@@ -162,9 +147,6 @@ configureNAT () {
  echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
  chmod 644 /var/lib/misc/dnsmasq.leases

  # Store IP for Docker healthcheck
  echo "${VM_NET_IP}" > "/var/dsm.ip"

  NET_OPTS="-netdev tap,ifname=${VM_NET_TAP},script=no,downscript=no,id=hostnet0"

  # Build DNS options from container /etc/resolv.conf
@@ -247,12 +229,20 @@ else
  configureDHCP

  # Display the received IP on port 5000
  HTML="The location of DSM is http://${DHCP_IP}:5000<script>\
        setTimeout(function(){ window.location.replace('http://${DHCP_IP}:5000'); }, 2000);</script>"
  HTML="DSM is using another IP address.<br><br>(Check the logfile to see which one was assigned.)"

  pkill -f server.sh || true
  /run/server.sh 80 "${HTML}" > /dev/null &
  /run/server.sh 5000 "${HTML}" > /dev/null &

fi

[ "$DEBUG" = "Y" ] && echo && echo "Finished network setup.." && echo
NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"

if [ "$DHCP" = "Y" ]; then
  # Add extra LAN interface for Docker Healthcheck script
  NET_OPTS="${NET_OPTS} -netdev user,id=hostnet1,restrict=y,hostfwd=tcp::5555-:5000"
  NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet1,id=net1"
fi

[ "$DEBUG" = "Y" ] && echo && echo "Finished network setup.." && echo
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ _graceful_shutdown() {
      echo && echo "Please update the VirtualDSM Agent to allow for gracefull shutdowns..."

      kill -15 "$(cat "${_QEMU_PID}")"
      pkill -f qemu-system-x86_64
      pkill -f qemu-system-x86_64 || true

    fi
  fi
Loading