diff options
author | Simon Rettberg | 2022-02-23 16:17:05 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-02-23 16:17:05 +0100 |
commit | 0281e8057adcb79f92882845baab77b85397287c (patch) | |
tree | ab804898d7a06713fe5252f16d69b6c8ed971ca1 /core | |
parent | [remote-access] Explicitly add virtual output on intel cards (diff) | |
download | mltk-0281e8057adcb79f92882845baab77b85397287c.tar.gz mltk-0281e8057adcb79f92882845baab77b85397287c.tar.xz mltk-0281e8057adcb79f92882845baab77b85397287c.zip |
[dnbd3-proxy-mode] Split dnbd0 local caching split into own unit
Other approach also failed as service doesn't run as root, obviously
Diffstat (limited to 'core')
4 files changed, 37 insertions, 25 deletions
diff --git a/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-local-stage4.service b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-local-stage4.service new file mode 100644 index 00000000..532f5c13 --- /dev/null +++ b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-local-stage4.service @@ -0,0 +1,9 @@ +[Unit] +Description=add local DNBD3 proxy to dnbd0 for caching +Requires=dnbd3-proxy.service +After=dnbd3-proxy.service + +[Service] +Type=oneshot +ExecStart=/opt/openslx/scripts/systemd-dnbd3_local_stage4 +RemainAfterExit=true diff --git a/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-dnbd3_local_stage4 b/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-dnbd3_local_stage4 new file mode 100755 index 00000000..01b3d98a --- /dev/null +++ b/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-dnbd3_local_stage4 @@ -0,0 +1,26 @@ +#!/bin/ash + +# 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 + exit 1 + fi +fi + +exit 0 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 f1f6b63d..ad3bf36b 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 @@ -4,6 +4,7 @@ ERRLOG="/run/dnbd3-proxy.err" if [ -s "$ERRLOG" ]; then exec "$(which dnbd3-server)" -n --errormsg "$(cat "$ERRLOG")" -c /etc/dnbd3-server + exit 1 fi if [ -d "/mnt/dnbd3" ]; then @@ -12,30 +13,6 @@ else set -- fi -# 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 57320a54..02e1a361 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 @@ -286,7 +286,7 @@ if [ -n "$islocal" ]; then chown dnbd3:dnbd3 /mnt/dnbd3 adduser dnbd3 fuse # Start service, is not symlinked when not in proxy mode - systemctl --no-block start dnbd3-proxy.service + systemctl --no-block start dnbd3-proxy.service dnbd3-local-stage4.service fi exit 0 |