eventscripts: New function ctdb_check_counter()
authorMartin Schwenke <martin@meltin.net>
Tue, 6 Aug 2013 06:46:01 +0000 (16:46 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Wed, 14 Aug 2013 06:15:14 +0000 (16:15 +1000)
This provides much more flexible counter handling.

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

index 2acac25510fba976734fd4e83bdc5c246ce1b99f..9cf4ece90f5a918454cad4ebedfdac4a0d9cc472 100755 (executable)
@@ -802,6 +802,35 @@ ctdb_check_counter_equal () {
     return 0
 }
 
+ctdb_check_counter () {
+    _msg="${1:-error}"  # "error"  - anything else is silent on fail
+    _op="${2:--ge}"  # an integer operator supported by test
+    _limit="${3:-${service_fail_limit}}"
+    shift 3
+    _ctdb_counter_common "$1"
+
+    # unary counting!
+    _size=$(stat -c "%s" "$_counter_file" 2>/dev/null || echo 0)
+    _hit=false
+    if [ "$_op" != "%" ] ; then
+       if [ $_size $_op $_limit ] ; then
+           _hit=true
+       fi
+    else
+       if [ $(($_size $_op $_limit)) -eq 0 ] ; then
+           _hit=true
+       fi
+    fi
+    if $_hit ; then
+       if [ "$_msg" = "error" ] ; then
+           echo "ERROR: $_size consecutive failures for $_service_name, marking node unhealthy"
+           exit 1
+       else
+           return 1
+       fi
+    fi
+}
+
 ########################################################
 
 ctdb_spool_dir="/var/spool/ctdb"