ctdb-scripts: Fix CTDB_DBDIR=tmpfs support
[samba.git] / ctdb / config / ctdbd_wrapper
index 71c7b25bcd1b6f17ec418d8ef6264639475ed9e4..be251e6472c89fb2b2548f00646256888bc35884 100755 (executable)
@@ -25,7 +25,6 @@ loadconfig "ctdb"
 [ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
 
 ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
-ctdb_rundir="/usr/local/var/run/ctdb"
 
 ############################################################
 
@@ -80,61 +79,37 @@ ctdbd_is_running ()
 
 ############################################################
 
-# Mount given database directories on tmpfs
+# If necessary, mount volatile database directory on tmpfs
 dbdir_tmpfs_start ()
 {
-    for _var ; do
-       # $_var is the name of the configuration varable, so get the
-       # value
-       eval _val="\$${_var}"
-
-       case "$_val" in
-           tmpfs|tmpfs:*)
-               _opts_defaults="mode=700"
-               # Get any extra options specified after colon
-               if [ "$_val" = "tmpfs" ] ; then
-                   _opts=""
-               else
-                   _opts="${_val#tmpfs:}"
-               fi
-               # It is OK to repeat options - last value wins
-               _opts_all="${_opts_defaults}${_opts:+,}${_opts}"
-
-               # Last component of mountpoint is variable name
-               _mnt="${ctdb_rundir}/${_var}"
-               mkdir -p "$_mnt" || exit $?
-
-               # If already mounted then remount, otherwise mount
-               if findmnt -t tmpfs "$_mnt" >/dev/null ; then
-                   mount -t tmpfs -o "remount,$_opts_all" none "$_mnt" || \
-                       exit $?
-               else
-                   mount -t tmpfs -o "$_opts_all" none "$_mnt" || exit $?
-               fi
-
-               # Replace specified value with mountpoint, to be
-               # passed to ctdbd
-               eval "${_var}=${_mnt}"
-               ;;
-       esac
-    done
+    if [ -z "$CTDB_DBDIR_TMPFS_OPTIONS" ] ; then
+       return
+    fi
+
+    # Shortcut for readability
+    _opts="$CTDB_DBDIR_TMPFS_OPTIONS"
+
+    mkdir -p "$CTDB_DBDIR" || exit $?
+
+    # If already mounted then remount, otherwise mount
+    if findmnt -t tmpfs "$CTDB_DBDIR" >/dev/null ; then
+       mount -t tmpfs -o "remount,$_opts" none "$CTDB_DBDIR" || \
+           exit $?
+    else
+       mount -t tmpfs -o "$_opts" none "$CTDB_DBDIR" || exit $?
+    fi
 }
 
-# Unmount database tmpfs directories on exit
+# If necessary, unmount volatile database tmpfs directory on exit
 dbdir_tmpfs_stop ()
 {
-    for _var ; do
-       eval _val="\$${_var}"
-
-       case "$_val" in
-           tmpfs|tmpfs:*)
-               _mnt="${ctdb_rundir}/${_var}"
-               if [ -d "$_mnt" ] && findmnt -t tmpfs "$_mnt" >/dev/null ; then
-                   umount "$_mnt"
-               fi
-               ;;
-       esac
-    done
+    if [ -z "$CTDB_DBDIR_TMPFS_OPTIONS" ] ; then
+       return
+    fi
+
+    if [ -d "$CTDB_DBDIR" ] && findmnt -t tmpfs "$CTDB_DBDIR" >/dev/null ; then
+       umount "$CTDB_DBDIR"
+    fi
 }
 
 build_ctdb_options ()
@@ -223,7 +198,7 @@ start()
     # there may still be other processes around, so do some cleanup.
     kill_ctdbd "$_session"
 
-    dbdir_tmpfs_start CTDB_DBDIR
+    dbdir_tmpfs_start
 
     build_ctdb_options
 
@@ -334,7 +309,7 @@ stop()
        fi
     fi
 
-    dbdir_tmpfs_stop CTDB_DBDIR
+    dbdir_tmpfs_stop
 
     return 0
 }