1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ctdb-scripts: Simplify TCP port checking

Commit 86792724a2 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>
This commit is contained in:
Martin Schwenke 2016-12-17 22:40:05 +11:00 committed by Martin Schwenke
parent e70e77383c
commit 26b7841aa6
5 changed files with 35 additions and 59 deletions

View File

@ -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
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
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
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
# 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
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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