ctdb-scripts: Allow load_script_options() to specify an event script
authorMartin Schwenke <martin@meltin.net>
Wed, 4 Apr 2018 09:06:13 +0000 (19:06 +1000)
committerAmitay Isaacs <amitay@samba.org>
Sat, 12 May 2018 04:11:17 +0000 (06:11 +0200)
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 <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/functions
ctdb/tests/eventscripts/scripts/local.sh

index 77588aee6f2e8e0e5a554f31f720d2a075c32f47..f3d7c163ec4f92fae079e5bea5bb5960a19cbb74 100755 (executable)
@@ -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"
index 49c84baa95e14f4891a73c90b5961f88a1c48807..101769bf9e2bcba852da883e84773cd77fdcc89c 100644 (file)
@@ -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"