diff options
author | Martin Schwenke <martin@meltin.net> | 2011-07-05 11:32:06 +1000 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2011-08-17 10:39:53 +1000 |
commit | 5c9fbb55ce1b173646cb789185886fa4a3c56b6f (patch) | |
tree | 7aadc3a015f8ef5d6bbc22811bb3e44bc1e97d08 | |
parent | f0f9271301488bbeb4bf4faed2b8c5682166f749 (diff) | |
download | samba-5c9fbb55ce1b173646cb789185886fa4a3c56b6f.tar.gz samba-5c9fbb55ce1b173646cb789185886fa4a3c56b6f.tar.xz samba-5c9fbb55ce1b173646cb789185886fa4a3c56b6f.zip |
Eventscript functions: optimise ctdb_check_tcp_ports() and add debug.
ctdb_check_tcp_ports() runs "netstat -a -t -n" in a loop for each
port. There are 2 problems with this:
* Netstat is run on each loop iteration when it need only be run once.
* The -a option is used to list all connections but the function only
cares about the listening ports. There may be many thousands of
non-listening ports to grep through.
This changes ctdb_check_tcp_ports() to run netstat with the -l option
instead of the -a option. It also only runs netstat once before the
main loop.
When a port is found to not be listening the output of the netstat
command is now dumped to help with debugging.
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 830355a8b18c53cfcc3ad1e3009bbb1a7a681fa0)
-rwxr-xr-x | ctdb/config/functions | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/ctdb/config/functions b/ctdb/config/functions index c6cddd462d..fcb67bb7af 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -324,15 +324,26 @@ ctdb_check_directories() { # check a set of tcp ports # usage: ctdb_check_tcp_ports <ports...> ###################################################### -ctdb_check_tcp_ports() { - - for p ; do - if ! netstat -a -t -n | grep -q "0\.0\.0\.0:$p .*LISTEN" ; then - if ! netstat -a -t -n | grep -q ":::$p .*LISTEN" ; then - echo "ERROR: $service_name tcp port $p is not responding" - return 1 - fi - fi +ctdb_check_tcp_ports() +{ + _cmd='netstat -l -t -n' + _ns=$($_cmd) + for _p ; do # process each function argument (port) + for _a in '0\.0\.0\.0' '::' ; do + _pat="[[:space:]]${_a}:${_p}[[:space:]]+[^[:space:]]+[[:space:]]+LISTEN" + if echo "$_ns" | grep -E -q "$_pat" ; then + # We matched the port, so process next port + continue 2 + fi + done + + # We didn't match the port, so flag an error, print some debug + cat <<EOF +ERROR: $service_name tcp port $_p is not responding +$_cmd shows this output: +$_ns +EOF + return 1 done } |