ctdb-scripts: Convert 40.vsftpd to use threshold-based fail counting
authorMartin Schwenke <mschwenke@ddn.com>
Mon, 24 Jul 2023 23:52:56 +0000 (09:52 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 3 Oct 2023 04:53:38 +0000 (04:53 +0000)
This effectively provides simple testing for the threshold-based
approach.

Add new script option CTDB_VSFTPD_MONITOR_THRESHOLDS.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Tue Oct  3 04:53:38 UTC 2023 on atb-devel-224

ctdb/config/events/legacy/40.vsftpd.script
ctdb/doc/ctdb-script.options.5.xml
ctdb/tests/UNIT/eventscripts/40.vsftpd.monitor.002.sh
ctdb/tests/UNIT/eventscripts/scripts/40.vsftpd.sh

index 1202812c3cd11cf01010506f524969cc7ecd8a00..2d2aac470339f4b2a0db4b300871cf79a748e5d6 100755 (executable)
@@ -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
index 3a39d6feb48eccf7e06dc6719baa54061c045843..a01b10a949c750cfca95cebe524a6e22e8f873fc 100644 (file)
@@ -611,6 +611,37 @@ CTDB_PER_IP_ROUTING_TABLE_ID_HIGH=9000
 
     </refsect2>
 
+    <refsect2>
+      <title>40.vsftpd</title>
+
+      <para>
+       Provides CTDB's vsftpd service management.
+      </para>
+
+      <variablelist>
+       <varlistentry>
+         <term>
+           CTDB_VSFTPD_MONITOR_THRESHOLDS=<parameter>THRESHOLDS</parameter>
+         </term>
+         <listitem>
+           <para>
+             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 <citetitle>Monitoring
+             Thresholds</citetitle> for a description of how
+             monitoring thresholds work.
+           </para>
+           <para>
+             Default is 1:2.
+           </para>
+         </listitem>
+       </varlistentry>
+
+      </variablelist>
+
+    </refsect2>
+
     <refsect2>
       <title>48.netbios</title>
 
index 4426e1b103c4af04c9cf29dcb93ae34bd4b296bc..f825be4d02a1d0d943c80248926fb4f1c461a2f8 100755 (executable)
@@ -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 <<EOF
 vsftpd not listening on TCP port 21
-WARNING: vsftpd not listening but less than 2 consecutive failures, not unhealthy yet
+WARNING: vsftpd listening on TCP port 21: fail count 1 >= threshold 1
+EOF
+simple_test
+
+setup "up"
+
+ok <<EOF
+NOTICE: vsftpd listening on TCP port 21: no longer failing
+EOF
+simple_test
+
+setup "down"
+
+ok <<EOF
+vsftpd not listening on TCP port 21
+WARNING: vsftpd listening on TCP port 21: fail count 1 >= threshold 1
+EOF
+simple_test
+
+required_result 1 <<EOF
+vsftpd not listening on TCP port 21
+ERROR: vsftpd listening on TCP port 21: fail count 2 >= threshold 2
 EOF
 simple_test
 
 required_result 1 <<EOF
 vsftpd not listening on TCP port 21
-ERROR: 2 consecutive failures for vsftpd, marking node unhealthy
+ERROR: vsftpd listening on TCP port 21: fail count 3 >= threshold 2
+EOF
+simple_test
+
+setup "up"
+
+ok <<EOF
+NOTICE: vsftpd listening on TCP port 21: no longer failing
 EOF
 simple_test
index 2d26b6f1bcb768ac24e5dfa234604a60f15878c3..236d1303ab25e0abfea199c58149251770de56d6 100644 (file)
@@ -6,7 +6,9 @@ setup()
 
        if [ "$1" != "down" ]; then
                service "$_service_name" start
+               setup_tcp_listen 21
        else
                service "$_service_name" force-stopped
+               setup_tcp_listen ""
        fi
 }