From: Martin Schwenke Date: Wed, 4 Apr 2018 09:06:13 +0000 (+1000) Subject: ctdb-scripts: Allow load_script_options() to specify an event script X-Git-Tag: ldb-1.4.0~284 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=02444e5f479f2d9705de93006916d9cd1333f21c;p=thirdparty%2Fsamba.git ctdb-scripts: Allow load_script_options() to specify an event script This allows other scripts to use the given options for a particular event script. One interesting example is that the ctdb_natgw tool should look for configuration in events.d/11.natgw.options. In the future this will be something like events/failover/11.natgw.options, so require the component to be specified even though it isn't yet used. Test support is also updated. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/functions b/ctdb/config/functions index 77588aee6f2..f3d7c163ec4 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -54,8 +54,19 @@ loadconfig() { fi } +# 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 + loadconfig _options="${CTDB_BASE}/script.options" @@ -64,7 +75,12 @@ load_script_options () . "$_options" fi - _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" diff --git a/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh index 49c84baa95e..101769bf9e2 100644 --- a/ctdb/tests/eventscripts/scripts/local.sh +++ b/ctdb/tests/eventscripts/scripts/local.sh @@ -71,11 +71,24 @@ fi # General setup fakery -# The current implementation just assumes each non-comment line of -# input is a variable assignment and evals it with export prepended. +# Default is to use script name with ".options" appended. With +# arguments, this can specify an alternate script name (and +# component). setup_script_options () { - _options="${script_dir}/${script%.script}.options" + if [ $# -eq 2 ] ; then + _script="$2" + elif [ $# -eq 0 ] ; then + _script="" + else + die "usage: setup_script_options [ component script ]" + fi + + if [ -n "$_script" ] ; then + _options="${CTDB_BASE}/events.d/${_script}.options" + else + _options="${script_dir}/${script%.script}.options" + fi cat >>"$_options"