summaryrefslogtreecommitdiffstats
path: root/core/modules/dnbd3-proxy-mode
diff options
context:
space:
mode:
authorSimon Rettberg2022-02-22 14:26:24 +0100
committerSimon Rettberg2022-02-22 14:26:24 +0100
commitcf0f5d8173eaf2655f384b5ec388dd67bdba956f (patch)
tree87dd52548d5b0602ae60dee9650ec209c26d424e /core/modules/dnbd3-proxy-mode
parent[dhcp-busybox] Add service to create additional bridges (diff)
downloadmltk-cf0f5d8173eaf2655f384b5ec388dd67bdba956f.tar.gz
mltk-cf0f5d8173eaf2655f384b5ec388dd67bdba956f.tar.xz
mltk-cf0f5d8173eaf2655f384b5ec388dd67bdba956f.zip
[dnbd3-proxy-mode] Move stag4 local caching to dnbd3-server.service
The switching to the local proxy was blocking the actual startup of the proxy.
Diffstat (limited to 'core/modules/dnbd3-proxy-mode')
-rwxr-xr-xcore/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-dnbd3_proxy29
-rwxr-xr-xcore/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-setup_dnbd3_proxy24
2 files changed, 32 insertions, 21 deletions
diff --git a/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-dnbd3_proxy b/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-dnbd3_proxy
index e094aa44..f1f6b63d 100755
--- a/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-dnbd3_proxy
+++ b/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-dnbd3_proxy
@@ -3,7 +3,7 @@
ERRLOG="/run/dnbd3-proxy.err"
if [ -s "$ERRLOG" ]; then
- exec $(which dnbd3-server) -n --errormsg "$(cat "$ERRLOG")" -c /etc/dnbd3-server
+ exec "$(which dnbd3-server)" -n --errormsg "$(cat "$ERRLOG")" -c /etc/dnbd3-server
fi
if [ -d "/mnt/dnbd3" ]; then
@@ -11,7 +11,32 @@ if [ -d "/mnt/dnbd3" ]; then
else
set --
fi
-exec $(which dnbd3-server) -n -c /etc/dnbd3-server "$@"
+
+# Force immediate switch to localhost for stage4 if applicable
+if [ -d "/mnt/dnbd3" ] && [ -b /dev/dnbd0 ] \
+ && [ "$( cat /sys/block/dnbd0/net/rid )" -gt 0 ]; then
+(
+ DNBD3_PORT=5003
+ # give it some time to start
+ usleep 250000
+ if ! grep -q -F 127.0.0.1 /sys/block/dnbd0/net/alt_servers; then
+ # add the server
+ if ! dnbd3-client -A "127.0.0.1:$DNBD3_PORT" -d /dev/dnbd0; then
+ echo "WARN: Cannot add localhost to dnbd0" >&2
+ fi
+ fi
+ for i in 1 2 3 4 5 6 7; do
+ echo | busybox timeout 1 busybox nc 127.0.0.1 "$DNBD3_PORT" && break
+ echo "WARN: port wait fail #$i"
+ usleep ${i}00000 # tenths of a second
+ done
+ if ! dnbd3-client -s "127.0.0.1:$DNBD3_PORT" -d /dev/dnbd0; then
+ echo "ERROR: Cannot switch dnbd0 to localhost" >&2
+ fi
+) &
+fi
+
+exec "$(which dnbd3-server)" -n -c /etc/dnbd3-server "$@"
exit 1
diff --git a/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-setup_dnbd3_proxy b/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-setup_dnbd3_proxy
index a36007d9..57320a54 100755
--- a/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-setup_dnbd3_proxy
+++ b/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-setup_dnbd3_proxy
@@ -27,6 +27,10 @@ if [ "$SLX_RUNMODE_MODULE" != "dnbd3" ]; then
mingb="$SLX_DNBD3_MIN_GB"
fi
+# This should never exist at bootup, but to be sure, try to remove it
+# so we don't assume local caching in the dnbd3-server startup script
+rmdir /mnt/dnbd3 2> /dev/null
+
# Log error to server and local file in /run.
# The main startup script will check whether this file is > 0 bytes
# and start in errormsg-mode.
@@ -60,7 +64,7 @@ if ! mkdir -p "${DNBD3_CONF_DIR}"; then
fi
# We prefer ID45 for storage (if >= 10GB), otherwise
-# fallback to /tmp if it's persistent and >= 10GB.
+# fallback to /tmp if it's not in RAM and >= 10GB.
# For local caching, /tmp is never used.
d="/opt/openslx/persistent"
dsd="$(disksize "$d")"
@@ -283,24 +287,6 @@ if [ -n "$islocal" ]; then
adduser dnbd3 fuse
# Start service, is not symlinked when not in proxy mode
systemctl --no-block start dnbd3-proxy.service
- if [ -b /dev/dnbd0 ] && [ "$( cat /sys/block/dnbd0/net/rid )" -gt 0 ]; then
- # give it some time to start
- usleep 500000
- # add the server
- if ! dnbd3-client -A "127.0.0.1:$DNBD3_PORT" -d /dev/dnbd0; then
- echo "Cannot add localhost to dnbd0" >&2
- else
- for i in 1 2 3 4 5 ""; do
- echo | busybox timeout 1 busybox nc 127.0.0.1 "$DNBD3_PORT" && break
- echo "port wait fail #$i"
- [ -z "$i" ] && break
- sleep 1
- done
- if ! dnbd3-client -s "127.0.0.1:$DNBD3_PORT" -d /dev/dnbd0; then
- echo "Cannot switch dnbd0 to localhost" >&2
- fi
- fi
- fi
fi
exit 0