summaryrefslogtreecommitdiffstats
path: root/scripts/mount-store
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/mount-store')
-rwxr-xr-xscripts/mount-store71
1 files changed, 48 insertions, 23 deletions
diff --git a/scripts/mount-store b/scripts/mount-store
index ff628a9..b19ec83 100755
--- a/scripts/mount-store
+++ b/scripts/mount-store
@@ -67,6 +67,50 @@ storage_test () {
return $RET
}
+enable_nfs_export () {
+ # Enable nfs server
+ systemctl enable nfs-kernel-server.service
+ # Enable our export
+ sed -r -i 's,^\s*#\s*(/srv/openslx/nfs),\1,' "/etc/exports"
+ # Line was not present? add!
+ grep -Eq '^\s*/srv/openslx/nfs' "/etc/exports" \
+ || echo '/srv/openslx/nfs *(ro,async,insecure,no_root_squash,no_subtree_check)' >> "/etc/exports"
+ # Restart
+ systemctl --no-block restart nfs-kernel-server.service
+}
+
+disable_nfs_export () {
+ # Disable our export
+ sed -r -i 's,^\s*(/srv/openslx/nfs),#\1,' "/etc/exports"
+ # See if there are any foreign exports and nfs-server was running and if so, keep nfs server running
+ if grep -Eq '^\s*/' /etc/exports; then
+ if "$NFS_WAS_RUNNING"; then
+ systemctl --no-block restart nfs-kernel-server.service
+ fi
+ else
+ # No valid exports left, disable and stop NFS server
+ systemctl disable nfs-kernel-server.service
+ systemctl --no-block stop nfs-kernel-server.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
+ # Currently mounted, but neither CIFS or NFS...
+ if [ "$SOURCE" = "null" ]; then
+ echo "Internal storage requested, something of type $CURRENT_TYPE already mounted, doing nothing."
+ rm -f -- "$FLAG"
+ enable_nfs_export
+ systemctl --no-block restart dnbd3-server.service
+ exit 0
+ fi
+ echo "There's something of type $CURRENT_TYPE mounted at $DEST, but the satellite server's configuration"
+ echo "requests $SOURCE to be used as the VM store. If you modified your fstab or added a .mount service"
+ echo "to use a custom storage backend, please set the VM storage type in slx-admin to INTERNAL."
+ exit 1
+fi
+
systemctl stop dnbd3-server.service
# Already mounted?
@@ -118,33 +162,14 @@ fi
if [[ "${SOURCE}" == "null" ]]; then
rm -f -- "${FLAG}"
systemctl --no-block start dnbd3-server.service
- # Enable nfs server
- systemctl enable nfs-kernel-server.service
- # Enable our export
- sed -r -i 's,^\s*#\s*(/srv/openslx/nfs),\1,' "/etc/exports"
- # Line was not present? add!
- grep -Eq '^\s*/srv/openslx/nfs' "/etc/exports" \
- || echo '/srv/openslx/nfs *(ro,async,insecure,no_root_squash,no_subtree_check)' >> "/etc/exports"
- # Restart
- systemctl --no-block restart nfs-kernel-server.service
+ enable_nfs_export
echo "Success. Now using internal storage."
exit 0
fi
# Using external storage, via NFS or CIFS
-# Disable our export
-sed -r -i 's,^\s*(/srv/openslx/nfs),#\1,' "/etc/exports"
-# See if there are any foreign exports and nfs-server was running and if so, keep nfs server running
-if grep -Eq '^\s*/' /etc/exports; then
- if "$NFS_WAS_RUNNING"; then
- systemctl --no-block restart nfs-kernel-server.service
- fi
-else
- # No valid exports left, disable and stop NFS server
- systemctl disable nfs-kernel-server.service
- systemctl --no-block stop nfs-kernel-server.service
-fi
+disable_nfs_export
touch "${FLAG}"
@@ -185,7 +210,7 @@ remove_option () {
main () {
local RET=999
- if grep -E -q '^[^/].+:.+' <<<$SOURCE; then
+ if [[ "$SOURCE" =~ ^[^/].+:. ]]; then
# seems to be NFS
if [ "$RET" != 0 ] && [ -n "$MOUNT_OPTIONS" ]; then
remove_option bg retry ro
@@ -214,7 +239,7 @@ main () {
echo "$OPTSTR" > "$NFS_OPTS"
fi
fi
- elif grep -E -q '^//' <<<$SOURCE; then
+ elif [[ "$SOURCE" =~ ^//.+/. ]]; then
# seems to be SMB
export USER="$USERNAME"
export PASSWD="$PASSWORD"