[ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
-ctdb_rundir="/usr/local/var/run/ctdb"
############################################################
############################################################
-# 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 ()
# 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
fi
fi
- dbdir_tmpfs_stop CTDB_DBDIR
+ dbdir_tmpfs_stop
return 0
}
fi
CTDB_VARDIR="/usr/local/var/lib/ctdb"
+ctdb_rundir="/usr/local/var/run/ctdb"
# Only (and always) override these variables in test code
#######################################
# pull in a system config file, if any
+
+rewrite_ctdb_options ()
+{
+ case "$CTDB_DBDIR" in
+ tmpfs|tmpfs:*)
+ _opts_defaults="mode=700"
+ # Get any extra options specified after colon
+ if [ "$CTDB_DBDIR" = "tmpfs" ] ; then
+ _opts=""
+ else
+ _opts="${CTDB_DBDIR#tmpfs:}"
+ fi
+ # This is an internal variable, only used by ctdbd_wrapper.
+ # It is OK to repeat mount options - last value wins
+ CTDB_DBDIR_TMPFS_OPTIONS="${_opts_defaults}${_opts:+,}${_opts}"
+
+ CTDB_DBDIR="${ctdb_rundir}/CTDB_DBDIR"
+ ;;
+ *)
+ CTDB_DBDIR_TMPFS_OPTIONS=""
+ esac
+}
+
_loadconfig() {
if [ -z "$1" ] ; then
if [ -r "$_config" ] ; then
. "$_config"
fi
+ rewrite_ctdb_options
fi
}