From 9b263239ff4313108b3647c707035579f95b0aa4 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 14:26:19 +0200 Subject: [PATCH 01/23] Space --- run/power.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/power.sh b/run/power.sh index 08cfd03..7271830 100644 --- a/run/power.sh +++ b/run/power.sh @@ -48,7 +48,7 @@ _graceful_shutdown() { # Send a NMI interrupt which will be detected by the kernel echo 'nmi' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null - + else echo && echo "Please update the VirtualDSM Agent to allow for gracefull shutdowns..." From 8062e6c80a2df817b63273368e7daefce8f04e81 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 17:09:24 +0200 Subject: [PATCH 02/23] Use new API call --- run/power.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/power.sh b/run/power.sh index 7271830..79563e9 100644 --- a/run/power.sh +++ b/run/power.sh @@ -33,7 +33,7 @@ _graceful_shutdown() { # echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null # Send shutdown command to guest agent via serial port - RESPONSE=$(curl -s -m 2 -S http://127.0.0.1:2210/write?command=6 2>&1) + RESPONSE=$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=6 2>&1) if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then From d6d0e7f029e01f32125ed0e5e1463ad53d8c0122 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 17:12:19 +0200 Subject: [PATCH 03/23] Disable extra LAN interface --- run/network.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/run/network.sh b/run/network.sh index dda5d96..d4eeaee 100644 --- a/run/network.sh +++ b/run/network.sh @@ -244,16 +244,14 @@ fi NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0" -if [[ "${DHCP}" == [Yy1]* ]]; then - +#if [[ "${DHCP}" == [Yy1]* ]]; then + # # Add extra LAN interface for Docker Healthcheck script - - : ${MAC2:='02:11:32:CC:BB:AA'} - - 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,mac=${MAC2},id=net1" - -fi + # : ${MAC2:='02:11:32:CC:BB:AA'} + # 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,mac=${MAC2},id=net1" + # +#fi [[ "${DEBUG}" == [Yy1]* ]] && echo && echo "Finished network setup.." && echo From bba243ce9dea661d020a8c10b1009fb1813a9a8c Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 18:02:13 +0200 Subject: [PATCH 04/23] Retrieve IP from VM --- run/check.sh | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/run/check.sh b/run/check.sh index 0b74eb7..8cfc61b 100644 --- a/run/check.sh +++ b/run/check.sh @@ -1,18 +1,39 @@ #!/usr/bin/env bash set -u -# Docker Healthcheck +# Retrieve guest info for Docker healthcheck +RESPONSE=$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>&1) -: ${DHCP:='N'} - -if [[ "${DHCP}" == [Yy1]* ]]; then - PORT=5555 - IP="127.0.0.1" -else - PORT=5000 - IP="20.20.20.21" +if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then + echo "Failed to connect to guest: $RESPONSE" + exit 1 fi +# Retrieve the HTTP port number + +if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then + echo "Failed to parse response from guest: $RESPONSE" + exit 1 +fi + +rest=${RESPONSE#*http_port} +rest=${rest#*:} +rest=${rest%%,*} +PORT=${rest%%\"*} + +# Retrieve the IP address + +if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then + echo "Failed to parse response from guest: $RESPONSE" + exit 1 +fi + +rest=${RESPONSE#*eth0} +rest=${rest#*ip} +rest=${rest#*:} +rest=${rest#*\"} +IP=${rest%%\"*} + if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then echo "Failed to reach ${IP}:${PORT}" exit 1 From 7b9c0e00ac6075fa234dfc5d4c6f33ee3d3628b0 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 18:03:52 +0200 Subject: [PATCH 05/23] Remove extra LAN interface --- run/network.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/run/network.sh b/run/network.sh index d4eeaee..967b6d5 100644 --- a/run/network.sh +++ b/run/network.sh @@ -244,15 +244,6 @@ fi NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0" -#if [[ "${DHCP}" == [Yy1]* ]]; then - # - # Add extra LAN interface for Docker Healthcheck script - # : ${MAC2:='02:11:32:CC:BB:AA'} - # 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,mac=${MAC2},id=net1" - # -#fi - [[ "${DEBUG}" == [Yy1]* ]] && echo && echo "Finished network setup.." && echo return 0 From a5fe0432f3adc60058760b8160c5bbf5d80dd7ae Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 18:07:19 +0200 Subject: [PATCH 06/23] Show IP in DHCP mode --- run/network.sh | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/run/network.sh b/run/network.sh index 967b6d5..4832718 100644 --- a/run/network.sh +++ b/run/network.sh @@ -31,8 +31,8 @@ configureDHCP() { { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || : if (( rc != 0 )); then - echo -n "ERROR: Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan'." - echo " And that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15 + echo "ERROR: Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," + echo "ERROR: and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15 fi ip address add "${IP}" dev "${VM_NET_VLAN}" @@ -226,14 +226,9 @@ if [[ "${DHCP}" == [Yy1]* ]]; then # Configuration for DHCP IP configureDHCP - # Display the received IP on port 5000 - HTML="DSM is using another IP address.

Check the Docker logfile to see which one was
assigned, or download the\ - \ - Synology Assistant utility." - pkill -f server.sh || true - /run/server.sh 80 "${HTML}" > /dev/null & - /run/server.sh 5000 "${HTML}" > /dev/null & + /run/server.sh 80 ipinfo > /dev/null & + /run/server.sh 5000 ipinfo > /dev/null & else From 142b27f529470a652cd57b8052391a35ec5442ff Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 18:08:23 +0200 Subject: [PATCH 07/23] Docker healthcheck --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b4a1b26..2d41772 100644 --- a/Dockerfile +++ b/Dockerfile @@ -65,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=3 CMD /run/check.sh +HEALTHCHECK --interval=30s --retries=2 CMD /run/check.sh ENTRYPOINT ["/run/run.sh"] From 63ca30d62d8340fd3b61e7bc34cbb0a25a0e0e3d Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 19:30:25 +0200 Subject: [PATCH 08/23] Hide netcat output --- run/power.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/run/power.sh b/run/power.sh index 79563e9..004488b 100644 --- a/run/power.sh +++ b/run/power.sh @@ -47,9 +47,13 @@ _graceful_shutdown() { if ((AGENT_VERSION > 1)); then # Send a NMI interrupt which will be detected by the kernel - echo 'nmi' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null + if ! echo 'nmi' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null ; then + AGENT_VERSION=0 + fi - else + fi + + if ((AGENT_VERSION < 2)); then echo && echo "Please update the VirtualDSM Agent to allow for gracefull shutdowns..." @@ -65,7 +69,7 @@ _graceful_shutdown() { echo $(($(cat ${_QEMU_SHUTDOWN_COUNTER})+1)) > ${_QEMU_SHUTDOWN_COUNTER} # Try to connect to qemu - if echo 'info version'| nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null; then + if echo 'info version'| nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 ; then sleep 1 #echo "Shutting down, waiting... ($(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT})" @@ -75,7 +79,7 @@ _graceful_shutdown() { done echo && echo "Quitting..." - echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null || true + echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true return } From d1bcc3955ab31da24291f026bd7668dabdb2890d Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 19:32:46 +0200 Subject: [PATCH 09/23] Retrieve IP from VM --- run/server.sh | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/run/server.sh b/run/server.sh index ae3c6ae..34fb06b 100644 --- a/run/server.sh +++ b/run/server.sh @@ -1,17 +1,49 @@ #!/usr/bin/env bash set -eu -trap 'kill 0' EXIT +trap 'pkill -f nc || true' EXIT trap exit SIGINT SIGTERM -# Serve the page -HTML="VirtualDSM

$2

" +if [ "$2" != "ipinfo" ]; then -LENGTH="${#HTML}" + # Serve the page + HTML="VirtualDSM

$2

" -RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n" + LENGTH="${#HTML}" + RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n" -while true; do - echo -en "$RESPONSE" | nc -lp "${1:-5000}" & wait $! + while true; do + echo -en "$RESPONSE" | nc -lp "${1:-5000}" & wait $! + done + + exit 0 + +fi + +SH_SCRIPT="/run/ipinfo.sh" + +{ echo "INFO=\$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>&1)" + echo "rest=\${INFO#*http_port}" + echo "rest=\${rest#*:}" + echo "rest=\${rest%%,*}" + echo 'PORT=\${rest%%\"*}' + echo "rest=\${INFO#*eth0}" + echo "rest=\${rest#*ip}" + echo "rest=\${rest#*:}" + echo 'rest=\${rest#*\"}' + echo 'IP=\${rest%%\"*}' + echo "BODY=\"The location of DSM is http://\${IP}:\${PORT}\"" + echo "HTML=\"VirtualDSM

\$BODY

\"" + echo 'LENGTH="\${#HTML}"' + echo 'RESPONSE="HTTP/1.1 200 OK\nContent-Length: \${LENGTH}\nConnection: close\n\n\$HTML\n\n"' + echo 'echo \$RESPONSE' +} > "$SH_SCRIPT" + +chmod +x "$SH_SCRIPT" + +while true ; do + nc -lp "${1:-5000}" -e "$SH_SCRIPT" & wait $! done From 78555124142c924b9984da5a38b668a2ab8550e2 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 19:35:47 +0200 Subject: [PATCH 10/23] Add netcat-traditional --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2d41772..0aaec57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,8 +27,8 @@ RUN apt-get update && apt-get -y upgrade && \ net-tools \ btrfs-progs \ ca-certificates \ - netcat-openbsd \ qemu-system-x86 \ + netcat-traditional \ && apt-get clean COPY run/*.sh /run/ From 0cd215f962c4e81f7846b2eb329bad275d96e4d4 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 19:43:31 +0200 Subject: [PATCH 11/23] Check IP/Port --- run/check.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/run/check.sh b/run/check.sh index 8cfc61b..5ffab1f 100644 --- a/run/check.sh +++ b/run/check.sh @@ -21,6 +21,11 @@ rest=${rest#*:} rest=${rest%%,*} PORT=${rest%%\"*} +if [ -z "${PORT}" ]; then + echo "Guest has not set a portnumber yet.." + exit 1 +fi + # Retrieve the IP address if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then @@ -34,6 +39,11 @@ rest=${rest#*:} rest=${rest#*\"} IP=${rest%%\"*} +if [ -z "${IP}" ]; then + echo "Guest has not received an IP yet.." + exit 1 +fi + if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then echo "Failed to reach ${IP}:${PORT}" exit 1 From afcf200b1bcad3330a5146c9bbc50d88b048a863 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 21:00:37 +0200 Subject: [PATCH 12/23] Retrieve IP from VM --- run/server.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/run/server.sh b/run/server.sh index 34fb06b..2babc4a 100644 --- a/run/server.sh +++ b/run/server.sh @@ -14,36 +14,37 @@ if [ "$2" != "ipinfo" ]; then RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n" while true; do - echo -en "$RESPONSE" | nc -lp "${1:-5000}" & wait $! + echo -en "$RESPONSE" | nc -lp "${1:-5000}" >/dev/null 2>&1 & wait $! done exit 0 fi -SH_SCRIPT="/run/ipinfo.sh" +SH_SCRIPT="/tmp/ipinfo.sh" -{ echo "INFO=\$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>&1)" +{ echo "#!/bin/bash" + echo "INFO=\$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>/dev/null)" echo "rest=\${INFO#*http_port}" echo "rest=\${rest#*:}" echo "rest=\${rest%%,*}" - echo 'PORT=\${rest%%\"*}' + echo "PORT=\${rest%%\\\"*}" echo "rest=\${INFO#*eth0}" echo "rest=\${rest#*ip}" echo "rest=\${rest#*:}" - echo 'rest=\${rest#*\"}' - echo 'IP=\${rest%%\"*}' - echo "BODY=\"The location of DSM is http://\${IP}:\${PORT}\"" - echo "HTML=\"VirtualDSM

\$BODY

\"" - echo 'LENGTH="\${#HTML}"' - echo 'RESPONSE="HTTP/1.1 200 OK\nContent-Length: \${LENGTH}\nConnection: close\n\n\$HTML\n\n"' - echo 'echo \$RESPONSE' + echo "LENGTH=\"\${#HTML}\"" + echo "RESPONSE=\"HTTP/1.1 200 OK\\nContent-Length: \${LENGTH}\\nConnection: close\\n\\n\$HTML\\n\\n\"" + echo "echo -e \"\$RESPONSE\"" } > "$SH_SCRIPT" chmod +x "$SH_SCRIPT" while true ; do - nc -lp "${1:-5000}" -e "$SH_SCRIPT" & wait $! + nc -lp "${1:-5000}" -e "$SH_SCRIPT" >/dev/null 2>&1 & wait $! done From b797e72b28a8373d37de693eb74c5d5d0fdfef84 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 21:14:02 +0200 Subject: [PATCH 13/23] Support external scripts --- run/server.sh | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/run/server.sh b/run/server.sh index 2babc4a..dcfbd29 100644 --- a/run/server.sh +++ b/run/server.sh @@ -4,9 +4,14 @@ set -eu trap 'pkill -f nc || true' EXIT trap exit SIGINT SIGTERM -if [ "$2" != "ipinfo" ]; then +if [[ "$2" == "/"* ]]; then + + while true ; do + nc -lp "${1:-5000}" -e "$2" >/dev/null 2>&1 & wait $! + done + +else - # Serve the page HTML="VirtualDSM

$2

" @@ -17,34 +22,4 @@ if [ "$2" != "ipinfo" ]; then echo -en "$RESPONSE" | nc -lp "${1:-5000}" >/dev/null 2>&1 & wait $! done - exit 0 - fi - -SH_SCRIPT="/tmp/ipinfo.sh" - -{ echo "#!/bin/bash" - echo "INFO=\$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>/dev/null)" - echo "rest=\${INFO#*http_port}" - echo "rest=\${rest#*:}" - echo "rest=\${rest%%,*}" - echo "PORT=\${rest%%\\\"*}" - echo "rest=\${INFO#*eth0}" - echo "rest=\${rest#*ip}" - echo "rest=\${rest#*:}" - echo "rest=\${rest#*\\\"}" - echo "IP=\${rest%%\\\"*}" - echo "BODY=\"The location of DSM is http://\${IP}:\${PORT}\"" - echo "HTML=\"VirtualDSM

\$BODY

\"" - echo "LENGTH=\"\${#HTML}\"" - echo "RESPONSE=\"HTTP/1.1 200 OK\\nContent-Length: \${LENGTH}\\nConnection: close\\n\\n\$HTML\\n\\n\"" - echo "echo -e \"\$RESPONSE\"" -} > "$SH_SCRIPT" - -chmod +x "$SH_SCRIPT" - -while true ; do - nc -lp "${1:-5000}" -e "$SH_SCRIPT" >/dev/null 2>&1 & wait $! -done From d45fea5eba92c0d6dcbf61a486d7f32725842f33 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 21:18:38 +0200 Subject: [PATCH 14/23] Display IP info --- run/network.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/run/network.sh b/run/network.sh index 4832718..aa11c80 100644 --- a/run/network.sh +++ b/run/network.sh @@ -227,8 +227,25 @@ if [[ "${DHCP}" == [Yy1]* ]]; then configureDHCP pkill -f server.sh || true - /run/server.sh 80 ipinfo > /dev/null & - /run/server.sh 5000 ipinfo > /dev/null & + + SH_SCRIPT="/run/ipinfo.sh" + + { echo "#!/bin/bash" + echo "INFO=\$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>/dev/null)" + echo "rest=\${INFO#*http_port}; rest=\${rest#*:}; rest=\${rest%%,*}; PORT=\${rest%%\\\"*}" + echo "rest=\${INFO#*eth0}; rest=\${rest#*ip}; rest=\${rest#*:}; rest=\${rest#*\\\"}; IP=\${rest%%\\\"*}" + echo "BODY=\"The location of DSM is http://\${IP}:\${PORT}\"" + echo "HTML=\"VirtualDSM

\$BODY

\"" + echo "LENGTH=\"\${#HTML}\"; RESPONSE=\"HTTP/1.1 200 OK\\nContent-Length: \${LENGTH}\\nConnection: close\\n\\n\$HTML\\n\\n\"" + echo "echo -e \"\$RESPONSE\"" + } > "$SH_SCRIPT" + + chmod +x "$SH_SCRIPT" + + /run/server.sh 80 "$SH_SCRIPT" > /dev/null & + /run/server.sh 5000 "$SH_SCRIPT" > /dev/null & else From d6d955f3b1dda8c4c0863ad6277f94318d0d0b32 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 21:26:58 +0200 Subject: [PATCH 15/23] Hide netcat output --- run/power.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/power.sh b/run/power.sh index 004488b..817f167 100644 --- a/run/power.sh +++ b/run/power.sh @@ -52,7 +52,7 @@ _graceful_shutdown() { fi fi - + if ((AGENT_VERSION < 2)); then echo && echo "Please update the VirtualDSM Agent to allow for gracefull shutdowns..." From 398b68fd5b329a42e5e0ca008f449baf0afb1e34 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 22:17:21 +0200 Subject: [PATCH 16/23] Trap handler --- run/server.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/run/server.sh b/run/server.sh index dcfbd29..87eb66b 100644 --- a/run/server.sh +++ b/run/server.sh @@ -1,13 +1,17 @@ #!/usr/bin/env bash set -eu -trap 'pkill -f nc || true' EXIT -trap exit SIGINT SIGTERM +stop() { + trap - SIGINT EXIT + { pkill -f nc || true } 2>/dev/null +} + +trap 'stop' EXIT SIGINT SIGTERM SIGHUP if [[ "$2" == "/"* ]]; then while true ; do - nc -lp "${1:-5000}" -e "$2" >/dev/null 2>&1 & wait $! + nc -lp "${1:-5000}" -e "$2" & wait $! done else @@ -19,7 +23,7 @@ else RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n" while true; do - echo -en "$RESPONSE" | nc -lp "${1:-5000}" >/dev/null 2>&1 & wait $! + echo -en "$RESPONSE" | nc -lp "${1:-5000}" & wait $! done fi From aafcc633c281e0b0d9271beb5878497f59461f4d Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 22:19:37 +0200 Subject: [PATCH 17/23] Kill server process --- run/network.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run/network.sh b/run/network.sh index aa11c80..f799069 100644 --- a/run/network.sh +++ b/run/network.sh @@ -226,7 +226,7 @@ if [[ "${DHCP}" == [Yy1]* ]]; then # Configuration for DHCP IP configureDHCP - pkill -f server.sh || true + { pkill -f server.sh || true } 2>/dev/null SH_SCRIPT="/run/ipinfo.sh" @@ -244,8 +244,8 @@ if [[ "${DHCP}" == [Yy1]* ]]; then chmod +x "$SH_SCRIPT" - /run/server.sh 80 "$SH_SCRIPT" > /dev/null & - /run/server.sh 5000 "$SH_SCRIPT" > /dev/null & + /run/server.sh 80 "$SH_SCRIPT" & + /run/server.sh 5000 "$SH_SCRIPT" & else From 8bd47994b685b9a320967876f0efe21170091d84 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 22:21:52 +0200 Subject: [PATCH 18/23] Kill server process --- run/install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/run/install.sh b/run/install.sh index c153507..8c426f0 100644 --- a/run/install.sh +++ b/run/install.sh @@ -5,9 +5,10 @@ set -Eeuo pipefail 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 & +{ pkill -f server.sh || true } 2>/dev/null + +/run/server.sh 80 "${HTML}" & +/run/server.sh 5000 "${HTML}" & # Download the required files from the Synology website DL="https://global.synologydownload.com/download/DSM" From fd65d5b31dd2b05e7567d5b66140ce7f4ef1022b Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 22:33:32 +0200 Subject: [PATCH 19/23] Trap handler --- run/server.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/server.sh b/run/server.sh index 87eb66b..b6a8a4e 100644 --- a/run/server.sh +++ b/run/server.sh @@ -3,7 +3,7 @@ set -eu stop() { trap - SIGINT EXIT - { pkill -f nc || true } 2>/dev/null + { pkill -f nc || true; } 2>/dev/null } trap 'stop' EXIT SIGINT SIGTERM SIGHUP From 1ecb816513aa5c69a1434892cec458f014588750 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 22:34:03 +0200 Subject: [PATCH 20/23] Kill server process --- run/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/install.sh b/run/install.sh index 8c426f0..7d42c51 100644 --- a/run/install.sh +++ b/run/install.sh @@ -5,7 +5,7 @@ set -Eeuo pipefail HTML="Please wait while Virtual DSM is installing..." -{ pkill -f server.sh || true } 2>/dev/null +{ pkill -f server.sh || true; } 2>/dev/null /run/server.sh 80 "${HTML}" & /run/server.sh 5000 "${HTML}" & From 04cf3396c41be85da52f23ddb58f1429dd759f46 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 22:34:27 +0200 Subject: [PATCH 21/23] Kill server process --- run/network.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/network.sh b/run/network.sh index f799069..473d48c 100644 --- a/run/network.sh +++ b/run/network.sh @@ -226,7 +226,7 @@ if [[ "${DHCP}" == [Yy1]* ]]; then # Configuration for DHCP IP configureDHCP - { pkill -f server.sh || true } 2>/dev/null + { pkill -f server.sh || true; } 2>/dev/null SH_SCRIPT="/run/ipinfo.sh" From 86de4da3ca26953705be36722ae6c30f31d65fbd Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 22:46:59 +0200 Subject: [PATCH 22/23] Increase curl timeout --- run/check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/check.sh b/run/check.sh index 5ffab1f..b9024f3 100644 --- a/run/check.sh +++ b/run/check.sh @@ -2,7 +2,7 @@ set -u # Retrieve guest info for Docker healthcheck -RESPONSE=$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>&1) +RESPONSE=$(curl -s -m 6 -S http://127.0.0.1:2210/read?command=10 2>&1) if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then echo "Failed to connect to guest: $RESPONSE" From d375fd401bb29118eb651e39a909009f10dc1aa7 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 8 May 2023 23:17:49 +0200 Subject: [PATCH 23/23] SC2028 false positive --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 350da42..3011638 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -11,4 +11,4 @@ jobs: - name: Run ShellCheck uses: ludeeus/action-shellcheck@master env: - SHELLCHECK_OPTS: -x -e SC2001 -e SC2002 -e SC2223 -e SC2034 -e SC2064 -e SC2317 + SHELLCHECK_OPTS: -x -e SC2001 -e SC2002 -e SC2223 -e SC2034 -e SC2064 -e SC2317 -e SC2028