From: Martin Schwenke Date: Fri, 20 Apr 2018 02:12:44 +0000 (+1000) Subject: ctdb-scripts: Add function ctdb_get_db_options() X-Git-Url: http://git.samba.org/?p=metze%2Fsamba%2Fwip.git;a=commitdiff_plain;h=16aa9e7a303e13440d702ae444842af349db961c ctdb-scripts: Add function ctdb_get_db_options() This pulls database options from the configuration file, caches then and makes the values available in scripts. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/functions b/ctdb/config/functions index f3d7c163ec4f..649b367d4cb9 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -244,6 +244,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