From 3ee348a9663c69e20fe985d6a1fad6909579fca1 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 25 Jul 2023 09:52:56 +1000 Subject: [PATCH] ctdb-scripts: Convert 40.vsftpd to use threshold-based fail counting This effectively provides simple testing for the threshold-based approach. Add new script option CTDB_VSFTPD_MONITOR_THRESHOLDS. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs Autobuild-User(master): Amitay Isaacs Autobuild-Date(master): Tue Oct 3 04:53:38 UTC 2023 on atb-devel-224 --- ctdb/config/events/legacy/40.vsftpd.script | 17 ++++---- ctdb/doc/ctdb-script.options.5.xml | 31 +++++++++++++++ .../eventscripts/40.vsftpd.monitor.002.sh | 39 +++++++++++++++++-- .../UNIT/eventscripts/scripts/40.vsftpd.sh | 2 + 4 files changed, 77 insertions(+), 12 deletions(-) diff --git a/ctdb/config/events/legacy/40.vsftpd.script b/ctdb/config/events/legacy/40.vsftpd.script index 1202812c3cd..2d2aac47033 100755 --- a/ctdb/config/events/legacy/40.vsftpd.script +++ b/ctdb/config/events/legacy/40.vsftpd.script @@ -19,11 +19,13 @@ load_script_options ctdb_setup_state_dir "service" "$service_name" +port_21="vsftpd listening on TCP port 21" + case "$1" in startup) service "$service_name" stop > /dev/null 2>&1 service "$service_name" start - ctdb_counter_init + failcount_init "$port_21" ;; shutdown) @@ -42,15 +44,12 @@ ipreallocated) monitor) if ctdb_check_tcp_ports 21 ; then - ctdb_counter_init + failcount_reset "$port_21" else - ctdb_counter_incr - num_fails=$(ctdb_counter_get) - if [ "$num_fails" -ge 2 ] ; then - die "ERROR: ${num_fails} consecutive failures for vsftpd, marking node unhealthy" - elif [ "$num_fails" -eq 1 ] ; then - echo "WARNING: vsftpd not listening but less than 2 consecutive failures, not unhealthy yet" - fi + # Set defaults, if unset + : "${CTDB_VSFTPD_MONITOR_THRESHOLDS:=1:2}" + + failcount_incr "$port_21" "$CTDB_VSFTPD_MONITOR_THRESHOLDS" fi ;; esac diff --git a/ctdb/doc/ctdb-script.options.5.xml b/ctdb/doc/ctdb-script.options.5.xml index 3a39d6feb48..a01b10a949c 100644 --- a/ctdb/doc/ctdb-script.options.5.xml +++ b/ctdb/doc/ctdb-script.options.5.xml @@ -611,6 +611,37 @@ CTDB_PER_IP_ROUTING_TABLE_ID_HIGH=9000 + + 40.vsftpd + + + Provides CTDB's vsftpd service management. + + + + + + CTDB_VSFTPD_MONITOR_THRESHOLDS=THRESHOLDS + + + + THRESHOLDS indicates how many consecutive monitoring + attempts need to report that vsftpd is not listening on + TCP port 21 before a warning is logged and before + monitoring fails. See the Monitoring + Thresholds for a description of how + monitoring thresholds work. + + + Default is 1:2. + + + + + + + + 48.netbios diff --git a/ctdb/tests/UNIT/eventscripts/40.vsftpd.monitor.002.sh b/ctdb/tests/UNIT/eventscripts/40.vsftpd.monitor.002.sh index 4426e1b103c..f825be4d02a 100755 --- a/ctdb/tests/UNIT/eventscripts/40.vsftpd.monitor.002.sh +++ b/ctdb/tests/UNIT/eventscripts/40.vsftpd.monitor.002.sh @@ -2,18 +2,51 @@ . "${TEST_SCRIPTS_DIR}/unit.sh" -define_test "managed, down - once, twice" +define_test "up once, down with recovery" + +setup "up" + +ok_null +simple_test setup "down" ok <= threshold 1 +EOF +simple_test + +setup "up" + +ok <= threshold 1 +EOF +simple_test + +required_result 1 <= threshold 2 EOF simple_test required_result 1 <= threshold 2 +EOF +simple_test + +setup "up" + +ok <