summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSimon Rettberg2021-11-12 15:55:54 +0100
committerSimon Rettberg2021-11-12 15:55:54 +0100
commit1d7f30a13e156ee1a359f6f59a4ff994eac1ca90 (patch)
tree40d9face16369b0d84406c0916b024d331d3ec9c /scripts
parent[install-https] Make sure newline is between cert and key (diff)
downloadtmlite-bwlp-1d7f30a13e156ee1a359f6f59a4ff994eac1ca90.tar.gz
tmlite-bwlp-1d7f30a13e156ee1a359f6f59a4ff994eac1ca90.tar.xz
tmlite-bwlp-1d7f30a13e156ee1a359f6f59a4ff994eac1ca90.zip
[mount-store] Take greater care where the .notmounted flag is written
While the task manager should make sure only one invocation if mount-store is running, add a few extra checks whether a mount-point is pulled under our feet, or mounted when we don't expect it. This includes making sure dmsd is not accessing the share while we're trying to manipulate it.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/mount-store19
1 files changed, 18 insertions, 1 deletions
diff --git a/scripts/mount-store b/scripts/mount-store
index 3cff451..6a21bf6 100755
--- a/scripts/mount-store
+++ b/scripts/mount-store
@@ -125,6 +125,12 @@ disable_nfs_export () {
fi
}
+start_dmsd () {
+ if "$DMSD_WAS_RUNNING"; then
+ systemctl --no-block start dmsd.service
+ fi
+}
+
# Quick safty measure -- if any local FS is mounted, do nothing and print warning if different type is requested
CURRENT_TYPE="$( awk -v DEST="$DEST" '$2 == DEST {print $3}' /proc/mounts )"
if [ -n "$CURRENT_TYPE" ] && ! [[ "$CURRENT_TYPE" == nfs* || "$CURRENT_TYPE" == cifs* ]]; then
@@ -148,8 +154,10 @@ systemctl stop dnbd3-server.service
# Already mounted?
TRIES=0
NFS_WAS_RUNNING=false
+DMSD_WAS_RUNNING=false
systemctl is-active -q nfs-kernel-server.service && NFS_WAS_RUNNING=true
-while awk '{print $2}' "/proc/mounts" | grep -Fxq "${DEST}"; do
+systemctl is-active -q dmsd.service && DMSD_WAS_RUNNING=true
+while mountpoint "${DEST}"; do
echo "Trying to unmount '$DEST'..."
systemctl stop nfs-kernel-server.service
if [ "$TRIES" -gt 5 ]; then
@@ -172,6 +180,7 @@ while awk '{print $2}' "/proc/mounts" | grep -Fxq "${DEST}"; do
RET=$?
fi
[ "$RET" = 0 ] && break
+ systemctl stop dmsd.service
sleep 1
TRIES=$(( TRIES + 1 ))
done
@@ -194,6 +203,7 @@ fi
if [[ "${SOURCE}" == "null" ]]; then
prepare_storage "local"
systemctl --no-block start dnbd3-server.service
+ start_dmsd
enable_nfs_export
echo "Success. Now using internal storage."
exit 0
@@ -203,6 +213,11 @@ fi
disable_nfs_export
+if mountpoint "${DEST}"; then
+ echo "**** Something was mounted to $DEST in the meantime. Aborting ****"
+ # Use the "nothing changed" exit code, as another concurrent invocation has changed stuff, apparently
+ exit 99
+fi
touch "${FLAG}"
if [[ "${SOURCE}" == "unknown" ]]; then
@@ -225,6 +240,7 @@ exec_mount () {
echo "Mount succeeded, checking write permissions...."
prepare_storage "$fstype"
RET=$?
+ mountpoint "$DEST" && rm -f -- "$FLAG"
[ "$RET" -eq "0" ] && return 0
umount -v "$DEST" || umount -v -f -l "$DEST"
return "$RET"
@@ -323,6 +339,7 @@ if [ "$RET" = "0" ]; then
echo "-- Share mounted successfully! --"
echo "----------------------------------"
systemctl --no-block start dnbd3-server.service
+ start_dmsd
fi
exit "$RET"