ctdb-scripts: Split CTDB configuration loading
authorMartin Schwenke <martin@meltin.net>
Tue, 6 Feb 2018 00:25:56 +0000 (11:25 +1100)
committerAmitay Isaacs <amitay@samba.org>
Wed, 28 Mar 2018 00:57:20 +0000 (02:57 +0200)
loadconfig() currently tries to load the CTDB configuration and also
any system configuration relevant to the current (event) script.

Instead add a new function load_system_config() to load the
distribution-specific system configuration for a component.  Call this
directly in the rare scripts that need the system configuration.

Also call load_system_config when loading the CTDB configuration to
pull in anything from the CTDB system configuration.  This is partly
for backward compatibility but also to get options that can be used
anywhere.

loadconfig() no longer takes an argument.  It simply loads the CTDB
configuration.

Drop support for falling back to /etc/ctdb/sysconfig/ctdb (or
similar).  Surely there's nobody who uses that!

Also, drop the indirection where loadconfig() calls _loadconfig().
This was used years ago as a test hook and is no longer required.

Inexplicably, this change introduces a new shellcheck test failure, so
silence this.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
13 files changed:
ctdb/config/ctdb-crash-cleanup.sh
ctdb/config/ctdb.init
ctdb/config/ctdbd_wrapper
ctdb/config/debug-hung-script.sh
ctdb/config/debug_locks.sh
ctdb/config/events.d/60.nfs
ctdb/config/events.d/91.lvs
ctdb/config/events.d/99.timeout
ctdb/config/functions
ctdb/config/statd-callout
ctdb/tools/ctdb_lvs
ctdb/tools/ctdb_natgw
ctdb/tools/onnode

index 2ab8e527d3291a063c8d03d668601582db8d7e64..8f4cc8645661c2ff9bcfa2fd2d2306da773393c5 100755 (executable)
@@ -14,7 +14,7 @@ if service ctdb status >/dev/null 2>&1 ; then
     exit 0
 fi
 
-loadconfig ctdb
+loadconfig
 
 if [ ! -f "$CTDB_BASE/public_addresses" ] ; then
        die "No public addresses file found. Can't clean up."
index dcb32e46ead02290a243fbad596fd84592f4fbac..7fe8f0085ae33fa9d28f7a60272938a0b7a8439c 100755 (executable)
@@ -41,14 +41,16 @@ unset TMPDIR
 [ -n "$CTDB_BASE" ] || export CTDB_BASE="/etc/ctdb"
 
 . "${CTDB_BASE}/functions"
-loadconfig "network"
-loadconfig "ctdb"
+
+load_system_config "network"
 
 # check networking is up (for redhat)
 if [ "$NETWORKING" = "no" ] ; then
     exit 0
 fi
 
+load_system_config "ctdb"
+
 detect_init_style
 export CTDB_INIT_STYLE
 
index c239e3d4a3b45405d2be050d51dde5a6c36a668f..8f3c6cb4d2eb5ae03c105959d7fad942d27d5e3c 100755 (executable)
@@ -19,7 +19,8 @@ if [ -z "$CTDB_BASE" ] ; then
 fi
 
 . "${CTDB_BASE}/functions"
-loadconfig "ctdb"
+
+loadconfig
 
 ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
 
index 2e3792c71109ea918bb811c2fb29ef84ccbe87ad..dc9c6e1ac7fbd1fd0948ad36971f9a47384c4e0c 100755 (executable)
@@ -8,7 +8,7 @@
 
 . "${CTDB_BASE}/functions"
 
-loadconfig ctdb
+loadconfig
 
 # Testing hook
 if [ -n "$CTDB_DEBUG_HUNG_SCRIPT_LOGFILE" ] ; then
index f678724c434674e22f024c7acd725631915e9474..0f8aaad67d22676f4a8b382746d82af5d35c7bf4 100755 (executable)
@@ -17,7 +17,7 @@
 CTDB_DBDIR="${CTDB_VARDIR}"
 CTDB_DBDIR_PERSISTENT="${CTDB_VARDIR}/persistent"
 
-loadconfig ctdb
+loadconfig
 
 (
     flock -n 9 || exit 1
index ee048e2197532ae12d559d5724aad4a4c71f62da..b4a7cd6a47166a9a67cb68ce97a9e23426f0ce2a 100755 (executable)
@@ -8,6 +8,8 @@
 
 service_name="nfs"
 
+load_system_config "nfs"
+
 loadconfig
 
 ctdb_setup_state_dir "service" "$service_name"
index 9725ee88508cbdfc1b22ebfd30b9ce9117dd2b30..f48be1160132ff45fd9cb91c43a04b700b24f143 100755 (executable)
@@ -6,7 +6,7 @@
 
 . "${CTDB_BASE}/functions"
 
-loadconfig ctdb
+loadconfig
 
 [ -n "$CTDB_LVS_NODES" ] || exit 0
 export CTDB_LVS_NODES
index 4aa594085d823cb48aed24a4d95725f32371e8ca..c2fe0913e1cc32d2ab883ee2265e1894c1f6eeba 100755 (executable)
@@ -9,7 +9,7 @@
 
 . "${CTDB_BASE}/functions"
 
-loadconfig ctdb
+loadconfig
 
 [ "$CTDB_RUN_TIMEOUT_MONITOR" = "yes" ] || exit 0
 
index 7014d788c8045c4bbc464958ab1143c96b30faa6..86780001ab642c40fec5e7d08ca0a94c0e3f5f24 100755 (executable)
@@ -56,43 +56,28 @@ rewrite_ctdb_options ()
     esac
 }
 
-_loadconfig() {
-
-    if [ -z "$1" ] ; then
-       foo="${service_config:-${service_name}}"
-       if [ -n "$foo" ] ; then
-           loadconfig "$foo"
-           return
+load_system_config ()
+{
+       if [ -z "$1" ] ; then
+               return
        fi
-    fi
 
-    if [ "$1" != "ctdb" ] ; then
-       loadconfig "ctdb"
-    fi
+       if [ -f "${CTDB_SYS_ETCDIR}/sysconfig/$1" ]; then
+               . "${CTDB_SYS_ETCDIR}/sysconfig/$1"
+       elif [ -f "${CTDB_SYS_ETCDIR}/default/$1" ]; then
+               . "${CTDB_SYS_ETCDIR}/default/$1"
+       fi
+}
 
-    if [ -z "$1" ] ; then
-       return
-    fi
+loadconfig() {
 
-    if [ -f "${CTDB_SYS_ETCDIR}/sysconfig/$1" ]; then
-       . "${CTDB_SYS_ETCDIR}/sysconfig/$1"
-    elif [ -f "${CTDB_SYS_ETCDIR}/default/$1" ]; then
-       . "${CTDB_SYS_ETCDIR}/default/$1"
-    elif [ -f "${CTDB_BASE}/sysconfig/$1" ]; then
-       . "${CTDB_BASE}/sysconfig/$1"
-    fi
+       load_system_config "ctdb"
 
-    if [ "$1" = "ctdb" ] ; then
        _config="${CTDB_BASE}/ctdbd.conf"
        if [ -r "$_config" ] ; then
-           . "$_config"
+               . "$_config"
        fi
        rewrite_ctdb_options
-    fi
-}
-
-loadconfig () {
-    _loadconfig "$@"
 }
 
 ##############################################################
@@ -302,7 +287,9 @@ program_stack_traces ()
 # Ensure $service_name is set
 assert_service_name ()
 {
-    [ -n "$service_name" ] || die "INTERNAL ERROR: \$service_name not set"
+       # service_name is set by the event script
+       # shellcheck disable=SC2154
+       [ -n "$service_name" ] || die "INTERNAL ERROR: \$service_name not set"
 }
 
 ######################################################
index 422532d2bfa1697de092c13bb5f8a9192d232187..30d547742fe7e9914f1fcead0ef7f6c0b08afffe 100755 (executable)
@@ -20,8 +20,9 @@ die ()
     exit 1
 }
 
-loadconfig ctdb
-loadconfig nfs
+load_system_config "nfs"
+
+loadconfig
 
 [ -n "$NFS_HOSTNAME" ] || \
     die "NFS_HOSTNAME is not configured. statd-callout failed"
index 267f3fcb20abc9d27ff5b28d25dce04ff1bf0e1c..880069f24081ca7839c956891e89fad20b236128 100755 (executable)
@@ -5,7 +5,8 @@ if [ -z "$CTDB_BASE" ] ; then
 fi
 
 . "${CTDB_BASE}/functions"
-loadconfig "ctdb"
+
+loadconfig
 
 # Default LVS nodes file location
 [ -n "$CTDB_LVS_NODES" ] || CTDB_LVS_NODES="${CTDB_BASE}/lvs_nodes"
index 2497f83a6e47fc18cc17e10c4278671502119f74..b17624155bf2c3dd7a53e62d0a78bf241ba007ab 100755 (executable)
@@ -5,7 +5,8 @@ if [ -z "$CTDB_BASE" ] ; then
 fi
 
 . "${CTDB_BASE}/functions"
-loadconfig "ctdb"
+
+loadconfig
 
 # Default NAT gateway nodes file location
 [ -n "$CTDB_NATGW_NODES" ] || CTDB_NATGW_NODES="${CTDB_BASE}/natgw_nodes"
index 6f1b732705cdfd8978ea1bd4524c2ad3b1015fb1..c3ebfea71377306bb3df4d060c06d9646517b0fe 100755 (executable)
@@ -71,7 +71,8 @@ if [ -z "$CTDB_BASE" ] ; then
 fi
 
 . "${CTDB_BASE}/functions"
-loadconfig "ctdb"
+
+loadconfig
 
 parse_options ()
 {