ctdb-scripts: Simplify TCP port checking
authorMartin Schwenke <martin@meltin.net>
Sat, 17 Dec 2016 11:40:05 +0000 (22:40 +1100)
committerMartin Schwenke <martins@samba.org>
Mon, 16 Jan 2017 10:57:08 +0000 (11:57 +0100)
Commit 86792724a2a911da9cd3e75622d35084c88eb8ce added complications on
top of the multiple TCP port checking methods that used to exist.
Life is simpler now and the cause of any failures is obvious.  So just
print a simple message if the port check fails.

Tweak tests to match changes.  Drop one test that becomes a duplicate.

Temporarily tweak ctdb_check_command() so that it passes shellcheck
tests.  It will be removed anyway in a subsequent commit.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/functions
ctdb/tests/eventscripts/40.vsftpd.monitor.002.sh
ctdb/tests/eventscripts/50.samba.monitor.103.sh
ctdb/tests/eventscripts/50.samba.monitor.104.sh
ctdb/tests/eventscripts/50.samba.monitor.107.sh [deleted file]

index 17c6e26a9bef30569b8f028b3ed60ed2920b92c5..b64443998eda1eec2fc7e2fa9c1b1b6ba2e59aae 100755 (executable)
@@ -380,45 +380,36 @@ ctdb_check_tcp_init ()
 # using the "ctdb checktcpport" command.
 ctdb_check_tcp_ports()
 {
-    if [ -z "$1" ] ; then
-       echo "INTERNAL ERROR: ctdb_check_tcp_ports - no ports specified"
-       exit 1
-    fi
-
-    for _p ; do  # process each function argument (port)
-       _cmd="$CTDB checktcpport $_p"
-       _out=$($_cmd 2>&1)
-       _ret=$?
-       case "$_ret" in
-           0)
-               _ctdb_check_tcp_common
-               if [ ! -f "$_ctdb_service_started_file" ] ; then
-                   echo "ERROR: $service_name tcp port $_p is not responding"
-                   debug "\"ctdb checktcpport $_p\" was able to bind to port"
-               else
-                   echo "INFO: $service_name tcp port $_p is not responding"
-               fi
+       if [ -z "$1" ] ; then
+               echo "INTERNAL ERROR: ctdb_check_tcp_ports - no ports specified"
+               exit 1
+       fi
 
-               return 1
-               ;;
-           98)
-               # Couldn't bind, something already listening, next port...
-               continue
-               ;;
-           *)
-               echo "ERROR: unexpected error running \"ctdb checktcpport\""
-               debug <<EOF
-$CTDB checktcpport (exited with $_ret) with output:
-$_out"
-EOF
-               return $_ret
-       esac
-    done
+       for _p ; do  # process each function argument (port)
+               _cmd="$CTDB checktcpport $_p"
+               _out=$($_cmd 2>&1)
+               _ret=$?
+               case "$_ret" in
+               0)
+                       echo "$service_name not listening on TCP port $_p"
+                       return 1
+                       ;;
+               98)
+                       # Couldn't bind, something already listening, next port
+                       continue
+                       ;;
+               *)
+                       echo "unexpected error (${_ret}) running \"${_cmd}\""
+                       if [ -n "$_out" ] ; then
+                               echo "$_out"
+                       fi
+                       return $_ret
+                       ;;
+               esac
+       done
 
-    # All ports listening
-    _ctdb_check_tcp_common
-    rm -f "$_ctdb_service_started_file"
-    return 0
+       # All ports listening
+       return 0
 }
 
 ######################################################
@@ -443,7 +434,9 @@ ctdb_check_command ()
 {
     _out=$("$@" 2>&1) || {
        echo "ERROR: $* returned error"
-       echo "$_out" | debug
+       if [ -n "$_out" ] ; then
+               debug "$_out"
+       fi
        exit 1
     }
 }
index 7086eacc91eef65023a31c1faccddca873ce49d3..6ffed59bfcbc3f70a454b4521ecf3bf20a966973 100755 (executable)
@@ -8,13 +8,13 @@ setup_vsftpd "down"
 export CTDB_MANAGES_VSFTPD="yes"
 
 ok <<EOF
-ERROR: vsftpd tcp port 21 is not responding
+vsftpd not listening on TCP port 21
 WARNING: vsftpd not listening but less than 2 consecutive failures, not unhealthy yet
 EOF
 simple_test
 
 required_result 1 <<EOF
-ERROR: vsftpd tcp port 21 is not responding
+vsftpd not listening on TCP port 21
 ERROR: 2 consecutive failures for vsftpd, marking node unhealthy
 EOF
 simple_test
index 6f71a96760a39aa6e00db73592d94d04c8b9fb1a..ae953c2d3e5f871512ec790a4fcafed2648615d8 100755 (executable)
@@ -7,6 +7,6 @@ define_test "port 445 down"
 setup_samba
 tcp_port_down 445
 
-required_result 1 "ERROR: samba tcp port 445 is not responding"
+required_result 1 "samba not listening on TCP port 445"
 
 simple_test
index 9de022376be94a8768f12b3431ede5cb48ee4ded..dca2af517c3cde92e12ed90b759f28d003e40534 100755 (executable)
@@ -7,6 +7,6 @@ define_test "port 139 down"
 setup_samba
 tcp_port_down 139
 
-required_result 1 "ERROR: samba tcp port 139 is not responding"
+required_result 1 "samba not listening on TCP port 139"
 
 simple_test
diff --git a/ctdb/tests/eventscripts/50.samba.monitor.107.sh b/ctdb/tests/eventscripts/50.samba.monitor.107.sh
deleted file mode 100755 (executable)
index 19c948a..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-. "${TEST_SCRIPTS_DIR}/unit.sh"
-
-define_test "port 139 down, default tcp checker, debug"
-
-export CTDB_SCRIPT_DEBUGLEVEL=DEBUG
-
-setup_samba
-tcp_port_down 139
-
-required_result 1 <<EOF
-ERROR: samba tcp port 139 is not responding
-DEBUG: "ctdb checktcpport 139" was able to bind to port
-EOF
-
-simple_test