From ba1feecd02229474125f82b582b69383b4d45806 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 4 Jun 2018 13:00:08 +0200 Subject: [mount-store] Conditionally enable nfs server --- scripts/mount-store | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/mount-store b/scripts/mount-store index cc6766d..ff628a9 100755 --- a/scripts/mount-store +++ b/scripts/mount-store @@ -71,8 +71,11 @@ systemctl stop dnbd3-server.service # Already mounted? TRIES=0 +NFS_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 echo "Trying to unmount '$DEST'..." + systemctl stop nfs-kernel-server.service if [ "$TRIES" -gt 5 ]; then cat >&2 <<-HEREDOC Error: Cannot unmount '$DEST'! @@ -114,11 +117,35 @@ fi # Unmount and not requested to mount (local mode) if [[ "${SOURCE}" == "null" ]]; then rm -f -- "${FLAG}" - echo "Success. Now using internal storage." 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 + 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 + touch "${FLAG}" if [[ "${SOURCE}" == "unknown" ]]; then -- cgit v1.2.3-55-g7522