Eventscripts - enhance ctdb_replay_monitor_status()
[sahlberg/ctdb.git] / 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 ()