ctdb-scripts: Simplify 01.reclock.script
authorMartin Schwenke <martin@meltin.net>
Mon, 8 Jul 2019 06:35:57 +0000 (16:35 +1000)
committerMartin Schwenke <martins@samba.org>
Fri, 26 Jul 2019 04:52:04 +0000 (04:52 +0000)
The "init" event is only run once so don't bother caching the
configured value of the recovery lock.  Add some extra error checking.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Martin Schwenke <martins@samba.org>
Autobuild-Date(master): Fri Jul 26 04:52:04 UTC 2019 on sn-devel-184

ctdb/config/events/legacy/01.reclock.script

index 2f4ed355e5e4212e1481f69edf0f95289c4146e5..29822e1d48c8aacd5693af7842b169c3dfcfe22e 100755 (executable)
@@ -4,43 +4,29 @@
 [ -n "$CTDB_BASE" ] || \
     CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD")
 
-. "${CTDB_BASE}/functions"
-
-load_script_options
-
-ctdb_setup_state_dir "service" "reclock"
-
-ctdb_get_reclock_option ()
-{
-       _reclock_opt_file="${CTDB_SCRIPT_VARDIR}/recovery_lock.cache"
-
-       if [ -f "$_reclock_opt_file" ] ; then
-               . "$_reclock_opt_file"
-               return
-       fi
-
-       ctdb_translate_option "cluster" \
-                             "recovery lock" \
-                             "CTDB_RECOVERY_LOCK" >"$_reclock_opt_file"
-
-       . "$_reclock_opt_file"
-}
-
-ctdb_get_reclock_option
-
-# If CTDB_RECOVERY_LOCK specifies a helper then exit because this
-# script can't do anything useful.
-case "$CTDB_RECOVERY_LOCK" in
-!*) exit 0 ;;
-esac
-
 case "$1" in
 init)
-       if [ -n "$CTDB_RECOVERY_LOCK" ] ; then
-           d=$(dirname "$CTDB_RECOVERY_LOCK")
-           mkdir -vp "$d"
+       recovery_lock=$("${CTDB_HELPER_BINDIR}/ctdb-config" \
+                               get cluster "recovery lock")
+       # xshellcheck disable=SC2181
+       # Above is already complicated enough without embedding into "if"
+       case $? in
+       0) : ;;
+       2) exit 0 ;; # ENOENT: not configured
+       *) die "Unexpected error getting recovery lock configuration"
+       esac
+
+       if [ -z "$recovery_lock" ] ; then
+               exit 0
        fi
+
+       # If a helper is specified then exit because this script can't
+       # do anything useful
+       case "$recovery_lock" in
+       !*) exit 0 ;;
+       esac
+
+       d=$(dirname "$recovery_lock")
+       mkdir -vp "$d"
        ;;
 esac
-
-exit 0