From: Martin Schwenke Date: Sat, 17 Dec 2016 11:40:05 +0000 (+1100) Subject: ctdb-scripts: Simplify TCP port checking X-Git-Tag: talloc-2.1.9~387 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26b7841aa6e51dfd5330695f21acab620f7dbed4;p=thirdparty%2Fsamba.git ctdb-scripts: Simplify TCP port checking 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 Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/functions b/ctdb/config/functions index 17c6e26a9be..b64443998ed 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -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 <&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 } } diff --git a/ctdb/tests/eventscripts/40.vsftpd.monitor.002.sh b/ctdb/tests/eventscripts/40.vsftpd.monitor.002.sh index 7086eacc91e..6ffed59bfcb 100755 --- a/ctdb/tests/eventscripts/40.vsftpd.monitor.002.sh +++ b/ctdb/tests/eventscripts/40.vsftpd.monitor.002.sh @@ -8,13 +8,13 @@ setup_vsftpd "down" export CTDB_MANAGES_VSFTPD="yes" ok <