diff --git a/Dockerfile b/Dockerfile
index 7faa936..b4a1b26 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -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"]
diff --git a/run/check.sh b/run/check.sh
index b721717..3c2d69a 100644
--- a/run/check.sh
+++ b/run/check.sh
@@ -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
diff --git a/run/install.sh b/run/install.sh
index fd0a05c..31a9218 100644
--- a/run/install.sh
+++ b/run/install.sh
@@ -5,6 +5,8 @@ set -eu
HTML="Please wait while Virtual DSM is installing..."
+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
diff --git a/run/network.sh b/run/network.sh
index 7fea7ec..7916975 100644
--- a/run/network.sh
+++ b/run/network.sh
@@ -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=$( "/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"
+ HTML="DSM is using another IP address.
(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
diff --git a/run/power.sh b/run/power.sh
index c0a4b90..87fac55 100644
--- a/run/power.sh
+++ b/run/power.sh
@@ -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
diff --git a/run/server.sh b/run/server.sh
index 1c5f58d..953ff2b 100644
--- a/run/server.sh
+++ b/run/server.sh
@@ -1,17 +1,9 @@
#!/usr/bin/env bash
set -eu
+
+trap 'kill 0' EXIT
trap exit SIGINT SIGTERM
-# Close any previous instances
-script_name="${BASH_SOURCE[0]}"
-
-for pid in $(pidof -x "$script_name"); do
- if [ "$pid" != $$ ]; then
- kill -15 "$pid" 2> /dev/null
- wait "$pid" 2> /dev/null
- fi
-done
-
# Serve the page
HTML="