From: Martin Schwenke Date: Mon, 8 Jul 2019 06:35:57 +0000 (+1000) Subject: ctdb-scripts: Simplify 01.reclock.script X-Git-Tag: tdb-1.4.2~397 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea7708d8c7fa674111ccea58b3cd0757765c702a;p=thirdparty%2Fsamba.git ctdb-scripts: Simplify 01.reclock.script 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 Reviewed-by: Amitay Isaacs Autobuild-User(master): Martin Schwenke Autobuild-Date(master): Fri Jul 26 04:52:04 UTC 2019 on sn-devel-184 --- diff --git a/ctdb/config/events/legacy/01.reclock.script b/ctdb/config/events/legacy/01.reclock.script index 2f4ed355e5e..29822e1d48c 100755 --- a/ctdb/config/events/legacy/01.reclock.script +++ b/ctdb/config/events/legacy/01.reclock.script @@ -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