diff options
author | Martin Schwenke <martin@meltin.net> | 2010-12-17 16:10:56 +1100 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2011-08-11 10:46:56 +1000 |
commit | 2a14f9172286340ca5b7f24056e2195885d7918c (patch) | |
tree | ea5e3902c0f2923ebe69b9595bd7cb53c5920a1a | |
parent | 219c6fd55b94f0e5ad2c246c5f41c09a42d93ec1 (diff) | |
download | samba-2a14f9172286340ca5b7f24056e2195885d7918c.tar.gz samba-2a14f9172286340ca5b7f24056e2195885d7918c.tar.xz samba-2a14f9172286340ca5b7f24056e2195885d7918c.zip |
Eventscript functions: new function ctdb_check_counter().
This should eventually be able to replace ctdb_check_counter_limit()
and ctdb_check_counter_equal(), although it doesn't issue warnings
like the former.
It takes 4 optional arguments:
1. _msg - If "error" then over limit causes an error message and and
exit 1. Anything else fails silently but the function returns 1.
Default is "error".
2. _op - An integer operator supported by test (e.g. -eq, -ge, -gt).
Default is -ge.
3. _limit - Limit for the counter to be used in comparison. Default is
$service_fail_limit.
4. _service_name - Used to identify the counter. Default is
$service_name.
For example:
ctdb_check_counter error -ge 5 foo
will print a message and exit 1 if the counter for foo is >= 5,
whereas
ctdb_check_counter check -ge 5 foo
will just return 1 if the counter for foo is >= 5, and
ctdb_counter_check
with print a message and exit 1 if the counter for $service_name is >=
$service_fail_limit.
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 5b01b7233515669e995e037205796e265643b176)
-rwxr-xr-x | ctdb/config/functions | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ctdb/config/functions b/ctdb/config/functions index 39daeb7eb5..e685c07ace 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -545,6 +545,24 @@ ctdb_check_counter_equal () { fi 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) + if [ $_size $_op $_limit ] ; then + if [ "$_msg" = "error" ] ; then + echo "ERROR: $_limit consecutive failures for $_service_name, marking node unhealthy" + exit 1 + else + return 1 + fi + fi +} ######################################################## |