ctdb: Drop configuration file ctdbd.conf
[samba.git] / ctdb / config / functions
index 8728d99129b6ccf8e2fa9f48715f533a3dfa9fcf..30afcdec9623eb23a27073756612cf48f33870cc 100755 (executable)
@@ -11,7 +11,6 @@ export CTDB_BASE
 # CTDB_VARDIR is used elsewhere
 # shellcheck disable=SC2034
 CTDB_VARDIR="/usr/local/var/lib/ctdb"
-ctdb_rundir="/usr/local/var/run/ctdb"
 
 CTDB="${CTDB:-/usr/local/bin/ctdb}"
 
@@ -32,30 +31,6 @@ fi
 #######################################
 # 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
-           # It is OK to repeat mount options - last value wins.
-           # CTDB_DBDIR_TMPFS_OPTIONS is used by ctdbd_wrapper
-           # shellcheck disable=SC2034
-           CTDB_DBDIR_TMPFS_OPTIONS="${_opts_defaults}${_opts:+,}${_opts}"
-
-           CTDB_DBDIR="${ctdb_rundir}/CTDB_DBDIR"
-           ;;
-       *)
-           # shellcheck disable=SC2034
-           CTDB_DBDIR_TMPFS_OPTIONS=""
-    esac
-}
-
 load_system_config ()
 {
        if [ -z "$1" ] ; then
@@ -69,22 +44,31 @@ load_system_config ()
        fi
 }
 
-loadconfig() {
+# load_script_options [ component script ]
+#   script is an event script name relative to a component
+#   component is currently ignored
+load_script_options ()
+{
+       if [ $# -eq 2 ] ; then
+               _script="$2"
+       elif [ $# -eq 0  ] ; then
+               _script=""
+       else
+               die "usage: load_script_options [ component script ]"
+       fi
 
-       load_system_config "ctdb"
+       _options="${CTDB_BASE}/script.options"
 
-       _config="${CTDB_BASE}/ctdbd.conf"
-       if [ -r "$_config" ] ; then
-               . "$_config"
+       if [ -r "$_options" ] ; then
+               . "$_options"
        fi
-       rewrite_ctdb_options
-}
 
-load_script_options ()
-{
-       loadconfig
-
-       _options="${0%.script}.options"
+       if [ -n "$_script" ] ; then
+               _s="${CTDB_BASE}/events.d/${_script}"
+       else
+               _s="${0%.script}"
+       fi
+       _options="${_s}.options"
 
        if [ -r "$_options" ] ; then
                . "$_options"
@@ -248,6 +232,43 @@ ctdb_get_ip_address ()
     cat "$_ip_addr_file"
 }
 
+# Cached retrieval of database options for use by event scripts.
+#
+# If the variables are already set then they should not be overwritten
+# - this should only happen during event script testing.
+ctdb_get_db_options ()
+{
+       _db_opts_file="${CTDB_SCRIPT_VARDIR}/db_options.cache"
+
+       if [ ! -f "$_db_opts_file" ] ; then
+               {
+                       ctdb_translate_option "database" \
+                                             "volatile database directory" \
+                                             "CTDB_DBDIR"
+                       ctdb_translate_option "database" \
+                                             "persistent database directory" \
+                                             "CTDB_DBDIR_PERSISTENT"
+                       ctdb_translate_option "database" \
+                                             "state database directory" \
+                                             "CTDB_DBDIR_STATE"
+               } >"$_db_opts_file"
+       fi
+
+       . "$_db_opts_file"
+}
+
+ctdb_translate_option ()
+{
+       _section="$1"
+       _opt="$2"
+       _variable="$3"
+
+       # ctdb-config already prints an error if something goes wrong
+       _t=$("${CTDB_HELPER_BINDIR}/ctdb-config" get "$_section" "$_opt") || \
+               exit $?
+       echo "${_variable}=\"${_t}\""
+}
+
 ######################################################
 # wrapper around /proc/ settings to allow them to be hooked
 # for testing
@@ -986,10 +1007,6 @@ update_tickles ()
 # load a site local config file
 ########################################################
 
-[ -n "$CTDB_RC_LOCAL" -a -x "$CTDB_RC_LOCAL" ] && {
-       . "$CTDB_RC_LOCAL"
-}
-
 [ -x "${CTDB_BASE}/rc.local" ] && {
        . "${CTDB_BASE}/rc.local"
 }