Eventscripts - enhance ctdb_replay_monitor_status()
authorMartin Schwenke <martin@meltin.net>
Wed, 31 Aug 2011 05:34:43 +0000 (15:34 +1000)
committerMartin Schwenke <martin@meltin.net>
Wed, 31 Aug 2011 05:34:43 +0000 (15:34 +1000)
Print useful output and return a suitable exit code.

The DISABLED and TIMEDOUT statuses use fake negative return codes, and
these can't be faked from the shell.  So we map DISABLED to OK and
TIMEDOUT to ERROR - this should avoid nearly all surprises.  When we
do this we add a note to the beginning of the output.  The alternative
is to "fix" ctdbd to use only codes that can actually be returned by
shell scripts.  However, the reason for using negative codes is
probably to distinguish them from real ones...

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/functions

index 307b212f64dbb307c7667709aeaeda71709d8eea..5ca7d8e693e8bdbeb2d8661266dcd89083f9cdbe 100755 (executable)
@@ -1056,9 +1056,37 @@ ctdb_reconfigure_try_lock ()
 ctdb_replay_monitor_status ()
 {
     echo "Replaying previous status for this script due to reconfigure..."
-    ctdb scriptstatus -Y | \
-       grep -q -F ":${script_name}:0:OK:"
-    exit $?
+    # Leading colon (':') is missing in some versions...
+    _out=$(ctdb scriptstatus -Y | grep -E "^:?monitor:${script_name}:")
+    # Output looks like this:
+    # :monitor:60.nfs:1:ERROR:1314764004.030861:1314764004.035514:foo bar:
+    # This is the cheapest way of getting fields in the middle.
+    set -- $(IFS=":" ; echo $_out)
+    _code="$3"
+    _status="$4"
+    # The error output field can include colons so we'll try to
+    # preserve them.  The weak checking at the beginning tries to make
+    # this work for both broken (no leading ':') and fixed output.
+    _out="${_out%:}"
+    _err_out="${_out#*monitor:${script_name}:*:*:*:*:}"
+    case "$_status" in
+       OK) : ;;  # Do nothing special.
+       TIMEDOUT)
+           # Recast this as an error, since we can't exit with the
+           # correct negative number.
+           _code=1
+           _err_out="[Replay of TIMEDOUT scriptstatus - note incorrect return code.] ${_err_out}"
+           ;;
+       DISABLED)
+           # Recast this as an OK, since we can't exit with the
+           # correct negative number.
+           _code=0
+           _err_out="[Replay of DISABLED scriptstatus - note incorrect return code.] ${_err_out}"
+           ;;
+       *) : ;;  # Must be ERROR, do nothing special.
+    esac
+    echo "$_err_out"
+    exit $_code
 }
 
 ctdb_service_check_reconfigure ()