From 55ebe458ef799ef637cf442cf5cd451c79ab1b74 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 9 Jul 2008 14:18:15 +1000 Subject: Complete rewrite of tools/onnode. Remove old tools/onnode.ssh, tools/onnode.rsh. (This used to be ctdb commit 6b67f180668c7a05c941b4891bd2486601790165) --- ctdb/tools/onnode | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100755 ctdb/tools/onnode (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode new file mode 100755 index 0000000000..a94dd1e265 --- /dev/null +++ b/ctdb/tools/onnode @@ -0,0 +1,194 @@ +#!/bin/sh + +# Run commands on CTDB nodes. + +# See http://ctdb.samba.org/ for more information about CTDB. + +# Copyright (C) Martin Schwenke 2008 + +# Based on an earlier script by Andrew Tridgell and Ronnie Sahlberg. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . + +prog=$(basename $0) + +usage () +{ + cat >&2 < + + Options: + -c Run in current working directory on all nodes. + -p Run command in parallel on specified nodes. Implies -t. + -t Force tty allocation on nodes. Improves buffering. + -v Print node address even for a single node. + -q Do not print node addresses (overrides -v). + + all or a node number (0 base); or + list (comma separated) of ; or + range (hyphen separated) of node numbers. +EOF + exit 1 + +} + +invalid_nodespec () +{ + echo "Invalid " >&2 ; echo >&2 + usage +} + +# Defaults. +current=false +parallel=false +force_tty=false +verbose=false +quiet=false + +parse_options () +{ + # $POSIXLY_CORRECT means that the command passed to onnode can + # take options and getopt won't reorder things to make them + # options ot onnode. + temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cpqtv" -- "$@") + + [ $? != 0 ] && usage + + eval set -- "$temp" + + while true ; do + case "$1" in + -c) current=true ; shift ;; + -p) parallel=true ; force_tty=true ; shift ;; + -q) quiet=true ; shift ;; + -t) force_tty=true ; shift ;; + -v) verbose=true ; shift ;; + --) shift ; break ;; + *) usage ;; # Shouldn't happen, so this is reasonable. + esac + done + + [ $# -lt 2 ] && usage + + nodespec="$1" ; shift + command="$@" +} + +# Can probably be avoided if we use bash? +get_nth () +{ + n="$1" ; shift + + c=0 + for j ; do + if [ $n -eq $c ] ; then + echo $j + break + fi + c=$(($c + 1)) + done +} + +parse_nodespec () +{ + # Subshell avoids hacks to restore $IFS. + ( + IFS="," + for i in $1 ; do + case "$i" in + *-*) seq "${i%-*}" "${i#*-}" 2>/dev/null || invalid_nodespec ;; + all) echo all ;; + *) + [ $i -gt -1 ] 2>/dev/null || invalid_nodespec + echo $i + esac + done + ) +} + +get_nodes () +{ + [ -f "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes + all_nodes=$(egrep '^[[:alnum:]]' $CTDB_NODES_FILE) + + nodes="" + for n in $(parse_nodespec "$1") ; do + [ $? != 0 ] && exit 1 # Required to catch exit in above subshell. + case "$n" in + all) echo $all_nodes ;; + *) node=$(get_nth $n $all_nodes) + if [ -n "$node" ] ; then + echo $node + else + echo "${prog}: \"node ${n}\" does not exist" >&2 + exit 1 + fi + esac + + done +} + +###################################################################### + +parse_options "$@" + +$current && command="cd $PWD && $command" + +SSH_OPTS= +# Could "2>/dev/null || true" but want to see errors from typos in file. +[ -r /etc/ctdb/onnode.conf ] && . /etc/ctdb/onnode.conf +[ -n "$SSH" ] || SSH=ssh +if [ "$SSH" = "ssh" ] ; then + if $force_tty ; then + ssh_opts="-t" + else + ssh_opts="-n" + fi +else + : # rsh? All bets are off! +fi + +###################################################################### + +nodes=$(get_nodes "$nodespec") +[ $? != 0 ] && exit 1 # Required to catch exit in above subshell. + +if $quiet ; then + verbose=false +else + # If $nodes contains a space or a newline then assume multiple nodes. + nl=" +" + [ "$nodes" != "${nodes%[ ${nl}]*}" ] && verbose=true +fi + +pids="" +trap 'kill -TERM $pids 2>/dev/null' INT TERM +# There's a small race here where the kill can fail if no processes +# have been added to $pids and the script is interrupted. However, +# the part of the window where it matter is very small. +for n in $nodes ; do + if $verbose ; then + echo >&2 ; echo ">> NODE: $n <<" >&2 + fi + + if $parallel ; then + $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" & + pids="${pids} $!" + else + $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" + fi +done + +$parallel && wait -- cgit From f81d0022c487dc0f3de7b462c65f2a4c79e9aa5e Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 10 Jul 2008 14:19:52 +1000 Subject: When in verbose mode with -p, each line is prefixed with the node address/name. To implement this stderr has redirected to stdout - this doesn't need to be done but is the simplest implementation. Remove -t option since it doesn't seem to accomplish much but causes spurious messages to be displayed by ssh. Add explicit -h and --help options. Make style of usage message consistent with documentation. Document new features in doc/onnode.1.xml. (This used to be ctdb commit 8119238d1fa672814a7591593b517c3c42859315) --- ctdb/tools/onnode | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index a94dd1e265..1e7e24690f 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -8,6 +8,8 @@ # Based on an earlier script by Andrew Tridgell and Ronnie Sahlberg. +# Copyright (C) Andrew Tridgell 2007 + # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or @@ -26,17 +28,14 @@ prog=$(basename $0) usage () { cat >&2 < - - Options: +Usage: onnode [OPTION] ... ... + options: -c Run in current working directory on all nodes. -p Run command in parallel on specified nodes. Implies -t. - -t Force tty allocation on nodes. Improves buffering. - -v Print node address even for a single node. -q Do not print node addresses (overrides -v). - - all or a node number (0 base); or - list (comma separated) of ; or + -v Print node address even for a single node. + "all" or a node number (0 base); or + list (comma separated) of ; or range (hyphen separated) of node numbers. EOF exit 1 @@ -52,7 +51,6 @@ invalid_nodespec () # Defaults. current=false parallel=false -force_tty=false verbose=false quiet=false @@ -61,7 +59,7 @@ parse_options () # $POSIXLY_CORRECT means that the command passed to onnode can # take options and getopt won't reorder things to make them # options ot onnode. - temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cpqtv" -- "$@") + temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "chpqv" -l help -- "$@") [ $? != 0 ] && usage @@ -70,12 +68,11 @@ parse_options () while true ; do case "$1" in -c) current=true ; shift ;; - -p) parallel=true ; force_tty=true ; shift ;; + -p) parallel=true ; shift ;; -q) quiet=true ; shift ;; - -t) force_tty=true ; shift ;; -v) verbose=true ; shift ;; --) shift ; break ;; - *) usage ;; # Shouldn't happen, so this is reasonable. + -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable. esac done @@ -150,11 +147,7 @@ SSH_OPTS= [ -r /etc/ctdb/onnode.conf ] && . /etc/ctdb/onnode.conf [ -n "$SSH" ] || SSH=ssh if [ "$SSH" = "ssh" ] ; then - if $force_tty ; then - ssh_opts="-t" - else - ssh_opts="-n" - fi + ssh_opts="-n" else : # rsh? All bets are off! fi @@ -179,14 +172,18 @@ trap 'kill -TERM $pids 2>/dev/null' INT TERM # have been added to $pids and the script is interrupted. However, # the part of the window where it matter is very small. for n in $nodes ; do - if $verbose ; then - echo >&2 ; echo ">> NODE: $n <<" >&2 - fi - if $parallel ; then - $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" & + if $verbose ; then + ($SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" 2>&1 | sed -e "s@^@[$n] @" )& + else + $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" & + fi pids="${pids} $!" else + if $verbose ; then + echo >&2 ; echo ">> NODE: $n <<" >&2 + fi + $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" fi done -- cgit From db55b9131717aad044347422a9b77c6be51907ed Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 9 Jul 2008 14:18:15 +1000 Subject: Complete rewrite of tools/onnode. Remove old tools/onnode.ssh, tools/onnode.rsh. (This used to be ctdb commit 2cc9aba3d7e608eccc29c897f710b69f30653bbf) --- ctdb/tools/onnode | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100755 ctdb/tools/onnode (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode new file mode 100755 index 0000000000..a94dd1e265 --- /dev/null +++ b/ctdb/tools/onnode @@ -0,0 +1,194 @@ +#!/bin/sh + +# Run commands on CTDB nodes. + +# See http://ctdb.samba.org/ for more information about CTDB. + +# Copyright (C) Martin Schwenke 2008 + +# Based on an earlier script by Andrew Tridgell and Ronnie Sahlberg. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . + +prog=$(basename $0) + +usage () +{ + cat >&2 < + + Options: + -c Run in current working directory on all nodes. + -p Run command in parallel on specified nodes. Implies -t. + -t Force tty allocation on nodes. Improves buffering. + -v Print node address even for a single node. + -q Do not print node addresses (overrides -v). + + all or a node number (0 base); or + list (comma separated) of ; or + range (hyphen separated) of node numbers. +EOF + exit 1 + +} + +invalid_nodespec () +{ + echo "Invalid " >&2 ; echo >&2 + usage +} + +# Defaults. +current=false +parallel=false +force_tty=false +verbose=false +quiet=false + +parse_options () +{ + # $POSIXLY_CORRECT means that the command passed to onnode can + # take options and getopt won't reorder things to make them + # options ot onnode. + temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cpqtv" -- "$@") + + [ $? != 0 ] && usage + + eval set -- "$temp" + + while true ; do + case "$1" in + -c) current=true ; shift ;; + -p) parallel=true ; force_tty=true ; shift ;; + -q) quiet=true ; shift ;; + -t) force_tty=true ; shift ;; + -v) verbose=true ; shift ;; + --) shift ; break ;; + *) usage ;; # Shouldn't happen, so this is reasonable. + esac + done + + [ $# -lt 2 ] && usage + + nodespec="$1" ; shift + command="$@" +} + +# Can probably be avoided if we use bash? +get_nth () +{ + n="$1" ; shift + + c=0 + for j ; do + if [ $n -eq $c ] ; then + echo $j + break + fi + c=$(($c + 1)) + done +} + +parse_nodespec () +{ + # Subshell avoids hacks to restore $IFS. + ( + IFS="," + for i in $1 ; do + case "$i" in + *-*) seq "${i%-*}" "${i#*-}" 2>/dev/null || invalid_nodespec ;; + all) echo all ;; + *) + [ $i -gt -1 ] 2>/dev/null || invalid_nodespec + echo $i + esac + done + ) +} + +get_nodes () +{ + [ -f "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes + all_nodes=$(egrep '^[[:alnum:]]' $CTDB_NODES_FILE) + + nodes="" + for n in $(parse_nodespec "$1") ; do + [ $? != 0 ] && exit 1 # Required to catch exit in above subshell. + case "$n" in + all) echo $all_nodes ;; + *) node=$(get_nth $n $all_nodes) + if [ -n "$node" ] ; then + echo $node + else + echo "${prog}: \"node ${n}\" does not exist" >&2 + exit 1 + fi + esac + + done +} + +###################################################################### + +parse_options "$@" + +$current && command="cd $PWD && $command" + +SSH_OPTS= +# Could "2>/dev/null || true" but want to see errors from typos in file. +[ -r /etc/ctdb/onnode.conf ] && . /etc/ctdb/onnode.conf +[ -n "$SSH" ] || SSH=ssh +if [ "$SSH" = "ssh" ] ; then + if $force_tty ; then + ssh_opts="-t" + else + ssh_opts="-n" + fi +else + : # rsh? All bets are off! +fi + +###################################################################### + +nodes=$(get_nodes "$nodespec") +[ $? != 0 ] && exit 1 # Required to catch exit in above subshell. + +if $quiet ; then + verbose=false +else + # If $nodes contains a space or a newline then assume multiple nodes. + nl=" +" + [ "$nodes" != "${nodes%[ ${nl}]*}" ] && verbose=true +fi + +pids="" +trap 'kill -TERM $pids 2>/dev/null' INT TERM +# There's a small race here where the kill can fail if no processes +# have been added to $pids and the script is interrupted. However, +# the part of the window where it matter is very small. +for n in $nodes ; do + if $verbose ; then + echo >&2 ; echo ">> NODE: $n <<" >&2 + fi + + if $parallel ; then + $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" & + pids="${pids} $!" + else + $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" + fi +done + +$parallel && wait -- cgit From a92de86c2fa978761f005b23a265554b626dd433 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 10 Jul 2008 14:19:52 +1000 Subject: When in verbose mode with -p, each line is prefixed with the node address/name. To implement this stderr has redirected to stdout - this doesn't need to be done but is the simplest implementation. Remove -t option since it doesn't seem to accomplish much but causes spurious messages to be displayed by ssh. Add explicit -h and --help options. Make style of usage message consistent with documentation. Document new features in doc/onnode.1.xml. (This used to be ctdb commit dfaf2c1581e547df831b3171ad47acd27b4ca2af) --- ctdb/tools/onnode | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index a94dd1e265..1e7e24690f 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -8,6 +8,8 @@ # Based on an earlier script by Andrew Tridgell and Ronnie Sahlberg. +# Copyright (C) Andrew Tridgell 2007 + # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or @@ -26,17 +28,14 @@ prog=$(basename $0) usage () { cat >&2 < - - Options: +Usage: onnode [OPTION] ... ... + options: -c Run in current working directory on all nodes. -p Run command in parallel on specified nodes. Implies -t. - -t Force tty allocation on nodes. Improves buffering. - -v Print node address even for a single node. -q Do not print node addresses (overrides -v). - - all or a node number (0 base); or - list (comma separated) of ; or + -v Print node address even for a single node. + "all" or a node number (0 base); or + list (comma separated) of ; or range (hyphen separated) of node numbers. EOF exit 1 @@ -52,7 +51,6 @@ invalid_nodespec () # Defaults. current=false parallel=false -force_tty=false verbose=false quiet=false @@ -61,7 +59,7 @@ parse_options () # $POSIXLY_CORRECT means that the command passed to onnode can # take options and getopt won't reorder things to make them # options ot onnode. - temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cpqtv" -- "$@") + temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "chpqv" -l help -- "$@") [ $? != 0 ] && usage @@ -70,12 +68,11 @@ parse_options () while true ; do case "$1" in -c) current=true ; shift ;; - -p) parallel=true ; force_tty=true ; shift ;; + -p) parallel=true ; shift ;; -q) quiet=true ; shift ;; - -t) force_tty=true ; shift ;; -v) verbose=true ; shift ;; --) shift ; break ;; - *) usage ;; # Shouldn't happen, so this is reasonable. + -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable. esac done @@ -150,11 +147,7 @@ SSH_OPTS= [ -r /etc/ctdb/onnode.conf ] && . /etc/ctdb/onnode.conf [ -n "$SSH" ] || SSH=ssh if [ "$SSH" = "ssh" ] ; then - if $force_tty ; then - ssh_opts="-t" - else - ssh_opts="-n" - fi + ssh_opts="-n" else : # rsh? All bets are off! fi @@ -179,14 +172,18 @@ trap 'kill -TERM $pids 2>/dev/null' INT TERM # have been added to $pids and the script is interrupted. However, # the part of the window where it matter is very small. for n in $nodes ; do - if $verbose ; then - echo >&2 ; echo ">> NODE: $n <<" >&2 - fi - if $parallel ; then - $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" & + if $verbose ; then + ($SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" 2>&1 | sed -e "s@^@[$n] @" )& + else + $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" & + fi pids="${pids} $!" else + if $verbose ; then + echo >&2 ; echo ">> NODE: $n <<" >&2 + fi + $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" fi done -- cgit From ccb51aabe5b000a12c9e763dcedabf1b2f68c8c7 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 11 Jul 2008 12:52:01 +1000 Subject: Signed-off-by: Martin Schwenke In tools/onnode, remove reference to -t option in usage message. (This used to be ctdb commit f2e6b7e9d130eba9132eddda1a5e244a542a23ed) --- ctdb/tools/onnode | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 1e7e24690f..38f6a2a943 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -31,7 +31,7 @@ usage () Usage: onnode [OPTION] ... ... options: -c Run in current working directory on all nodes. - -p Run command in parallel on specified nodes. Implies -t. + -p Run command in parallel on specified nodes. -q Do not print node addresses (overrides -v). -v Print node address even for a single node. "all" or a node number (0 base); or -- cgit From 75fa8636774dc009b2290dc88ae0e9c6e355c1ae Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 11 Jul 2008 14:57:24 +1000 Subject: Signed-off-by: Martin Schwenke Minor fix to tools/onnode usage message. (This used to be ctdb commit 81dd4155e92fc9d11ac788a97a5fd3c50488cc80) --- ctdb/tools/onnode | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 38f6a2a943..4480d799f3 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -30,7 +30,7 @@ usage () cat >&2 < ... options: - -c Run in current working directory on all nodes. + -c Run in current working directory on specified nodes. -p Run command in parallel on specified nodes. -q Do not print node addresses (overrides -v). -v Print node address even for a single node. -- cgit From 3fa8aaa4e2f4931ac968bff2d85b98908c323d24 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 14 Jul 2008 09:19:22 +1000 Subject: fixed up exit status for onnode (This used to be ctdb commit c26afe26cc5c1f9cd9eef74166b5fc39dde591d3) --- ctdb/tools/onnode | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 1e7e24690f..6d8ed17f04 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Run commands on CTDB nodes. @@ -171,9 +171,12 @@ trap 'kill -TERM $pids 2>/dev/null' INT TERM # There's a small race here where the kill can fail if no processes # have been added to $pids and the script is interrupted. However, # the part of the window where it matter is very small. +retcode=0 for n in $nodes ; do if $parallel ; then if $verbose ; then + # pipefail is a bashism - is there some way to do this with plain sh? + set -o pipefail 2>/dev/null ($SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" 2>&1 | sed -e "s@^@[$n] @" )& else $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" & @@ -184,8 +187,17 @@ for n in $nodes ; do echo >&2 ; echo ">> NODE: $n <<" >&2 fi - $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" + $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" + [ $? = 0 ] || retcode=$? fi done -$parallel && wait +$parallel && { + for p in $pids; do + wait $p + [ $? = 0 ] || retcode=$? + done +} + +exit $retcode + -- cgit From 0013ec94de40491626a0d74962a56596adf8b839 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 12 Sep 2008 11:22:50 +1000 Subject: Changes to onnode. Add "healthy" and "connected" as possible nodespecs. Since we're now explicitly using bash, use local variables when sensible. Signed-off-by: Martin Schwenke (This used to be ctdb commit 16626eaf9c63adfe780e8f51f9cd97810647e731) --- ctdb/tools/onnode | 69 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 10 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 1096f91989..c60127ce09 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -34,7 +34,8 @@ Usage: onnode [OPTION] ... ... -p Run command in parallel on specified nodes. -q Do not print node addresses (overrides -v). -v Print node address even for a single node. - "all" or a node number (0 base); or + "all", "healthy", "connected"; + or a node number (0 base); or list (comma separated) of ; or range (hyphen separated) of node numbers. EOF @@ -59,7 +60,7 @@ parse_options () # $POSIXLY_CORRECT means that the command passed to onnode can # take options and getopt won't reorder things to make them # options ot onnode. - temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "chpqv" -l help -- "$@") + local temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "chpqv" -l help -- "$@") [ $? != 0 ] && usage @@ -85,9 +86,10 @@ parse_options () # Can probably be avoided if we use bash? get_nth () { - n="$1" ; shift + local n="$1" ; shift - c=0 + local c=0 + local j for j ; do if [ $n -eq $c ] ; then echo $j @@ -105,7 +107,7 @@ parse_nodespec () for i in $1 ; do case "$i" in *-*) seq "${i%-*}" "${i#*-}" 2>/dev/null || invalid_nodespec ;; - all) echo all ;; + all|healthy|connected) echo "$i" ;; *) [ $i -gt -1 ] 2>/dev/null || invalid_nodespec echo $i @@ -114,17 +116,65 @@ parse_nodespec () ) } +# Cache +ctdb_status_output="" +get_nodes_with_status () +{ + local all_nodes="$1" + local status="$2" + + local bits + case "$status" in + healthy) + bits="0:0:0:0" + ;; + connected) + bits="0:[0-1]:[0-1]:[0-1]" + ;; + *) + invalid_nodespec + esac + + if [ -z "$ctdb_status_output" ] ; then + ctdb_status_output=$(ctdb -Y status) + ctdb_status_output="${ctdb_status_output#* }" + fi + + local nodes="" + local i + for i in $ctdb_status_output ; do + # Try removing bits from end. + local t="${i%:${bits}:}" + if [ "$t" != "$i" ] ; then + # Succeeded. Get address. NOTE: this is an optimisation. + # It might be better to get the node number and then use + # get_nth() to get the address. This would make things + # more consistent if /etc/ctdb/nodes actually contained + # hostnames. + nodes="${nodes} ${t##*:}" + fi + done + + echo $nodes +} + get_nodes () { [ -f "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes - all_nodes=$(egrep '^[[:alnum:]]' $CTDB_NODES_FILE) + local all_nodes=$(egrep '^[[:alnum:]]' $CTDB_NODES_FILE) - nodes="" + local nodes="" + local n for n in $(parse_nodespec "$1") ; do [ $? != 0 ] && exit 1 # Required to catch exit in above subshell. case "$n" in - all) echo $all_nodes ;; - *) node=$(get_nth $n $all_nodes) + all) + echo $all_nodes ;; + healthy|connected) + get_nodes_with_status "$all_nodes" "$n" + ;; + *) + local node=$(get_nth $n $all_nodes) if [ -n "$node" ] ; then echo $node else @@ -200,4 +250,3 @@ $parallel && { } exit $retcode - -- cgit From 62a65ebc38cace60a0af74e29c43e52bb20c75cc Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 12 Sep 2008 16:55:18 +1000 Subject: onnode changes. "ok" is an alias for "healthy", "con" is an alias for "connected". Allow "rm" or "recmaster" to be a nodespec for the recovery master. Better error handling for interaction with ctdb client. Signed-off-by: Martin Schwenke (This used to be ctdb commit 05bdafed82106a0d8bfa53cd730eb3e1db68a51f) --- ctdb/tools/onnode | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index c60127ce09..6fb8fbe7bc 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -34,7 +34,8 @@ Usage: onnode [OPTION] ... ... -p Run command in parallel on specified nodes. -q Do not print node addresses (overrides -v). -v Print node address even for a single node. - "all", "healthy", "connected"; + "all", "ok" (or "healthy"), "con" (or "connected"), + "rm" (or "recmaster"); or a node number (0 base); or list (comma separated) of ; or range (hyphen separated) of node numbers. @@ -99,6 +100,17 @@ get_nth () done } +echo_nth () +{ + local node=$(get_nth "$@") + if [ -n "$node" ] ; then + echo $node + else + echo "${prog}: \"node ${n}\" does not exist" >&2 + exit 1 + fi +} + parse_nodespec () { # Subshell avoids hacks to restore $IFS. @@ -107,7 +119,7 @@ parse_nodespec () for i in $1 ; do case "$i" in *-*) seq "${i%-*}" "${i#*-}" 2>/dev/null || invalid_nodespec ;; - all|healthy|connected) echo "$i" ;; + all|ok|healthy|con|connected|rm|recmaster) echo "$i" ;; *) [ $i -gt -1 ] 2>/dev/null || invalid_nodespec echo $i @@ -125,10 +137,10 @@ get_nodes_with_status () local bits case "$status" in - healthy) + ok|healthy) bits="0:0:0:0" ;; - connected) + con|connected) bits="0:[0-1]:[0-1]:[0-1]" ;; *) @@ -136,7 +148,11 @@ get_nodes_with_status () esac if [ -z "$ctdb_status_output" ] ; then - ctdb_status_output=$(ctdb -Y status) + ctdb_status_output=$(ctdb -Y status 2>/dev/null) + if [ $? -ne 0 ] ; then + echo "${prog}: unable to get status of CTDB nodes" >&2 + exit 1 + fi ctdb_status_output="${ctdb_status_output#* }" fi @@ -158,6 +174,7 @@ get_nodes_with_status () echo $nodes } +ctdb_recmaster="" get_nodes () { [ -f "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes @@ -170,17 +187,24 @@ get_nodes () case "$n" in all) echo $all_nodes ;; - healthy|connected) - get_nodes_with_status "$all_nodes" "$n" + ok|healthy|con|connected) + get_nodes_with_status "$all_nodes" "$n" || exit 1 ;; - *) - local node=$(get_nth $n $all_nodes) - if [ -n "$node" ] ; then - echo $node + rm|recmaster) + if [ -z "$ctdb_recmaster" ] ; then + ctdb_recmaster=$(ctdb recmaster 2>/dev/null) + [ $? -eq 0 ] || ctdb_recmaster="" + fi + if [ -n "$ctdb_recmaster" ] ; then + echo_nth "$ctdb_recmaster" $all_nodes else - echo "${prog}: \"node ${n}\" does not exist" >&2 + echo "${prog}: No recmaster available" >&2 exit 1 fi + + ;; + *) + echo_nth $n $all_nodes esac done -- cgit From d741559fa6ba8d2077ecaa7053c1eab7d96aeb31 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 20 Nov 2008 20:40:01 +1100 Subject: Add some simple tests that can be run from within the tree. Signed-off-by: Martin Schwenke (This used to be ctdb commit eacb2ef82ea4809d874158756db973dd1e3fc8fc) --- ctdb/tools/onnode | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 6fb8fbe7bc..5bb5ebbfb8 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -148,6 +148,7 @@ get_nodes_with_status () esac if [ -z "$ctdb_status_output" ] ; then + # FIXME: need to do something if $CTDB_NODES_SOCKETS is set. ctdb_status_output=$(ctdb -Y status 2>/dev/null) if [ $? -ne 0 ] ; then echo "${prog}: unable to get status of CTDB nodes" >&2 @@ -177,8 +178,14 @@ get_nodes_with_status () ctdb_recmaster="" get_nodes () { - [ -f "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes - local all_nodes=$(egrep '^[[:alnum:]]' $CTDB_NODES_FILE) + local all_nodes + + if [ -n "$CTDB_NODES_SOCKETS" ] ; then + all_nodes="$CTDB_NODES_SOCKETS" + else + [ -f "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes + all_nodes=$(egrep '^[[:alnum:]]' $CTDB_NODES_FILE) + fi local nodes="" local n @@ -210,20 +217,29 @@ get_nodes () done } +fakessh () +{ + CTDB_SOCKET="$1" sh -c "$2" +} + ###################################################################### parse_options "$@" $current && command="cd $PWD && $command" -SSH_OPTS= -# Could "2>/dev/null || true" but want to see errors from typos in file. -[ -r /etc/ctdb/onnode.conf ] && . /etc/ctdb/onnode.conf -[ -n "$SSH" ] || SSH=ssh -if [ "$SSH" = "ssh" ] ; then - ssh_opts="-n" -else - : # rsh? All bets are off! +ssh_opts= +if [ -n "$CTDB_NODES_SOCKETS" ] ; then + SSH=fakessh +else + # Could "2>/dev/null || true" but want to see errors from typos in file. + [ -r /etc/ctdb/onnode.conf ] && . /etc/ctdb/onnode.conf + [ -n "$SSH" ] || SSH=ssh + if [ "$SSH" = "ssh" ] ; then + ssh_opts="-n" + else + : # rsh? All bets are off! + fi fi ###################################################################### -- cgit From 9616959bd6938e4c5c3713fe986c1e17cbdc574c Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 6 May 2009 13:17:34 +1000 Subject: New option "-o " saves stdout from each node to file .. Signed-off-by: Martin Schwenke (This used to be ctdb commit a0f5148ac749758e2dfbd6099e829c5bf1d900e6) --- ctdb/tools/onnode | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 5bb5ebbfb8..91d8ee815e 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -30,15 +30,16 @@ usage () cat >&2 < ... options: - -c Run in current working directory on specified nodes. - -p Run command in parallel on specified nodes. - -q Do not print node addresses (overrides -v). - -v Print node address even for a single node. - "all", "ok" (or "healthy"), "con" (or "connected"), - "rm" (or "recmaster"); - or a node number (0 base); or - list (comma separated) of ; or - range (hyphen separated) of node numbers. + -c Run in current working directory on specified nodes. + -o Save standard output from each node to file . + -p Run command in parallel on specified nodes. + -q Do not print node addresses (overrides -v). + -v Print node address even for a single node. + "all", "ok" (or "healthy"), "con" (or "connected"), + "rm" (or "recmaster"); + or a node number (0 base); or + list (comma separated) of ; or + range (hyphen separated) of node numbers. EOF exit 1 @@ -55,13 +56,14 @@ current=false parallel=false verbose=false quiet=false +prefix="" parse_options () { # $POSIXLY_CORRECT means that the command passed to onnode can # take options and getopt won't reorder things to make them # options ot onnode. - local temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "chpqv" -l help -- "$@") + local temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cho:pqv" -l help -- "$@") [ $? != 0 ] && usage @@ -70,6 +72,7 @@ parse_options () while true ; do case "$1" in -c) current=true ; shift ;; + -o) prefix="$2" ; shift 2 ;; -p) parallel=true ; shift ;; -q) quiet=true ; shift ;; -v) verbose=true ; shift ;; @@ -222,6 +225,26 @@ fakessh () CTDB_SOCKET="$1" sh -c "$2" } +stdout_filter () +{ + if [ -n "$prefix" ] ; then + cat >"${prefix}.${n}" + elif $verbose && $parallel ; then + sed -e "s@^@[$n] @" + else + cat + fi +} + +stderr_filter () +{ + if $verbose && $parallel ; then + sed -e "s@^@[$n] @" + else + cat + fi +} + ###################################################################### parse_options "$@" @@ -263,21 +286,16 @@ trap 'kill -TERM $pids 2>/dev/null' INT TERM # the part of the window where it matter is very small. retcode=0 for n in $nodes ; do + set -o pipefail 2>/dev/null if $parallel ; then - if $verbose ; then - # pipefail is a bashism - is there some way to do this with plain sh? - set -o pipefail 2>/dev/null - ($SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" 2>&1 | sed -e "s@^@[$n] @" )& - else - $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" & - fi + { exec 3>&1 ; { $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" | stdout_filter >&3 ; } 2>&1 | stderr_filter ; } & pids="${pids} $!" else if $verbose ; then echo >&2 ; echo ">> NODE: $n <<" >&2 fi - $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" + { exec 3>&1 ; { $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" | stdout_filter >&3 ; } 2>&1 | stderr_filter ; } [ $? = 0 ] || retcode=$? fi done -- cgit From 60984641758de60680604ae23014cd5a13b80802 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 11 May 2009 13:39:31 +1000 Subject: New lvs/lvsmaster and natgw/natgwlist nodespecs for onnode. Some code re-factoring to implement this and to make it easy to implement new ones. New simpler implementation of echo_nth() no longer uses deleted get_nth() function. Signed-off-by: Martin Schwenke (This used to be ctdb commit 29559f5dd099bec210e98909c9b2e048461b7c81) --- ctdb/tools/onnode | 88 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 37 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 91d8ee815e..b3fae33b32 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -36,7 +36,8 @@ Usage: onnode [OPTION] ... ... -q Do not print node addresses (overrides -v). -v Print node address even for a single node. "all", "ok" (or "healthy"), "con" (or "connected"), - "rm" (or "recmaster"); + "rm" (or "recmaster"), "lvs" (or "lvsmaster"), + "natgw" (or "natgwlist"); or a node number (0 base); or list (comma separated) of ; or range (hyphen separated) of node numbers. @@ -87,25 +88,13 @@ parse_options () command="$@" } -# Can probably be avoided if we use bash? -get_nth () +echo_nth () { local n="$1" ; shift - local c=0 - local j - for j ; do - if [ $n -eq $c ] ; then - echo $j - break - fi - c=$(($c + 1)) - done -} + shift $n + local node="$1" -echo_nth () -{ - local node=$(get_nth "$@") if [ -n "$node" ] ; then echo $node else @@ -122,7 +111,9 @@ parse_nodespec () for i in $1 ; do case "$i" in *-*) seq "${i%-*}" "${i#*-}" 2>/dev/null || invalid_nodespec ;; - all|ok|healthy|con|connected|rm|recmaster) echo "$i" ;; + # Separate lines for readability. + all|ok|healthy|con|connected) echo "$i" ;; + rm|recmaster|lvs|lvsmaster|natgw|natgwlist) echo "$i" ;; *) [ $i -gt -1 ] 2>/dev/null || invalid_nodespec echo $i @@ -131,8 +122,7 @@ parse_nodespec () ) } -# Cache -ctdb_status_output="" +ctdb_status_output="" # cache get_nodes_with_status () { local all_nodes="$1" @@ -140,10 +130,10 @@ get_nodes_with_status () local bits case "$status" in - ok|healthy) + healthy) bits="0:0:0:0" ;; - con|connected) + connected) bits="0:[0-1]:[0-1]:[0-1]" ;; *) @@ -167,8 +157,8 @@ get_nodes_with_status () local t="${i%:${bits}:}" if [ "$t" != "$i" ] ; then # Succeeded. Get address. NOTE: this is an optimisation. - # It might be better to get the node number and then use - # get_nth() to get the address. This would make things + # It might be better to get the node number and then get + # the nth node to get the address. This would make things # more consistent if /etc/ctdb/nodes actually contained # hostnames. nodes="${nodes} ${t##*:}" @@ -178,7 +168,32 @@ get_nodes_with_status () echo $nodes } -ctdb_recmaster="" +ctdb_props="" # cache +get_node_with_property () +{ + local all_nodes="$1" + local prop="$2" + + local prop_node="" + if [ "${ctdb_props##:${prop}:}" = "$ctdb_props" ] ; then + prop_node=$(ctdb "$prop" 2>/dev/null) + if [ $? -eq 0 ] ; then + ctdb_props="${ctdb_props}${ctdb_props:+ }:${prop}:${prop_node}" + else + prop_node="" + fi + else + prop_node="${ctdb_props##:${prop}:}" + prop_node="${prop_node%% *}" + fi + if [ -n "$prop_node" ] ; then + echo_nth "$prop_node" $all_nodes + else + echo "${prog}: No ${prop} available" >&2 + exit 1 + fi +} + get_nodes () { local all_nodes @@ -197,21 +212,20 @@ get_nodes () case "$n" in all) echo $all_nodes ;; - ok|healthy|con|connected) - get_nodes_with_status "$all_nodes" "$n" || exit 1 + ok|healthy) + get_nodes_with_status "$all_nodes" "healthy" || exit 1 + ;; + con|connected) + get_nodes_with_status "$all_nodes" "connected" || exit 1 ;; rm|recmaster) - if [ -z "$ctdb_recmaster" ] ; then - ctdb_recmaster=$(ctdb recmaster 2>/dev/null) - [ $? -eq 0 ] || ctdb_recmaster="" - fi - if [ -n "$ctdb_recmaster" ] ; then - echo_nth "$ctdb_recmaster" $all_nodes - else - echo "${prog}: No recmaster available" >&2 - exit 1 - fi - + get_node_with_property "$all_nodes" "recmaster" || exit 1 + ;; + lvs|lvsmaster) + get_node_with_property "$all_nodes" "lvsmaster" || exit 1 + ;; + natgw|natgwlist) + get_node_with_property "$all_nodes" "natgwlist" || exit 1 ;; *) echo_nth $n $all_nodes -- cgit From 53c96431041ed71a047c2637fd41bd64cca0a853 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 11 May 2009 14:43:17 +1000 Subject: Fix lvsmaster and natgwlist nodespecs. They both need to use a -Y option to ctdb and for natgwlist we only want the 1st line. Signed-off-by: Martin Schwenke (This used to be ctdb commit e781ff61e17d733349021bb036514f823c7cbfbb) --- ctdb/tools/onnode | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index b3fae33b32..d7adbb05af 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -176,7 +176,11 @@ get_node_with_property () local prop_node="" if [ "${ctdb_props##:${prop}:}" = "$ctdb_props" ] ; then - prop_node=$(ctdb "$prop" 2>/dev/null) + prop_node=$(ctdb "$prop" -Y 2>/dev/null) + # We only want the first line. + local nl=" +" + prop_node="${prop_node%%${nl}*}" if [ $? -eq 0 ] ; then ctdb_props="${ctdb_props}${ctdb_props:+ }:${prop}:${prop_node}" else -- cgit From 45aa5420649c9b7fbe578de8caf358d71f6397c1 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 2 Jun 2009 15:03:44 +1000 Subject: teach ONNODE about deleted nodes (This used to be ctdb commit 03d304e72a5839dc8d8d2e2312b346c21dca5774) --- ctdb/tools/onnode | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index d7adbb05af..aae7770653 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -95,7 +95,7 @@ echo_nth () shift $n local node="$1" - if [ -n "$node" ] ; then + if [ -n "$node" -a "$node" != "#DEAD" ] ; then echo $node else echo "${prog}: \"node ${n}\" does not exist" >&2 @@ -206,7 +206,7 @@ get_nodes () all_nodes="$CTDB_NODES_SOCKETS" else [ -f "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes - all_nodes=$(egrep '^[[:alnum:]]' $CTDB_NODES_FILE) + all_nodes=$(sed -e 's@#.*@@g' -e 's@ *@@g' -e 's@^$@#DEAD@' $CTDB_NODES_FILE) fi local nodes="" @@ -215,7 +215,8 @@ get_nodes () [ $? != 0 ] && exit 1 # Required to catch exit in above subshell. case "$n" in all) - echo $all_nodes ;; + echo "${all_nodes//#DEAD/}" + ;; ok|healthy) get_nodes_with_status "$all_nodes" "healthy" || exit 1 ;; -- cgit From 4697829e7cb982505bafe78e0a11a531d9fd25f4 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 19 Jun 2009 12:12:39 +1000 Subject: Fix minor onnode bugs relating to local daemons. Commit a0f5148ac749758e2dfbd6099e829c5bf1d900e6 caused a subtle regression. Due to the subtlety, this description is much longer than the 1 line patch that fixes it! The regression, where a process that invokes onnode is unexpectedly blocked, is only apparent if the following conditions are met: 1. $CTDB_NODES_SOCKETS is set; 2. The command passed to onnode attempts to background a process; and 3. onnode is run in certain types of subshell (e.g. foo=$(onnode ...)). In particular, when testing against local daemons (i.e. condition (1) is met), tests/simple/07_ctdb_process_exists.sh would fail (because it does both (2), (3)). The problem is caused by the use of file descriptor 3 in the code that allows separate filtering of stdout and stderr. A backgrounded process will have this descriptor open and the $(...) construct appears to wait for all file descriptors to be closed. This only happens with local daemons because SSH is replaced by a shell and file descriptor 3 leaks into that shell. It does not occur when SSH is used because the file descriptor does not leak into the remote shell where the process is backgrounded. The fix is simply to redirect file descriptor 3 to /dev/null in the fakessh function, which is used when $CTDB_NODES_SOCKETS is set. Also fixed is another minor bug when the -o option and $CTDB_NODES_SOCKETS are used in combination. The code uses the node name as a suffix for the output filename(s). Usually this is an IP address. However, when $CTDB_NODES_SOCKETS is in use the node name is the socket name, which might be a path several directories deep. Each output file is created via a simple redirection and this would fail if unexpected directories appear in the filename. 3 possible fixes were considered: 1. Replace all '/'s in the node name by '_'s. Nice and simple. 2. Use the basename of the node name. However, sockets may be in different directories but have the same basename. 3. Create all required directories before redirecting. This is a little more complex and probably doesn't meet the user's expectations. Option (1) is implemented here. Signed-off-by: Martin Schwenke (This used to be ctdb commit c97d56d93d9c1007a4e85affb19ed0c2d0e11b6d) --- ctdb/tools/onnode | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index aae7770653..b5f36c876b 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -241,13 +241,13 @@ get_nodes () fakessh () { - CTDB_SOCKET="$1" sh -c "$2" + CTDB_SOCKET="$1" sh -c "$2" 3>/dev/null } stdout_filter () { if [ -n "$prefix" ] ; then - cat >"${prefix}.${n}" + cat >"${prefix}.${n//\//_}" elif $verbose && $parallel ; then sed -e "s@^@[$n] @" else -- cgit From 50650fbbd1787896ca71f6e730238fba7d521cd8 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 28 Jul 2009 16:00:11 +1000 Subject: onnode: update tests for healthy and connected to cope with new stopped bit. Signed-off-by: Martin Schwenke (This used to be ctdb commit bfc926c866e361ab28330747544b268ba130bf30) --- ctdb/tools/onnode | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index b5f36c876b..e00cd2b1d9 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -131,10 +131,10 @@ get_nodes_with_status () local bits case "$status" in healthy) - bits="0:0:0:0" + bits="0:0:0:0:0" ;; connected) - bits="0:[0-1]:[0-1]:[0-1]" + bits="0:[0-1]:[0-1]:[0-1]:[0-1]" ;; *) invalid_nodespec -- cgit From 021892346cd61452ddae0ccdb5f631c666a28e16 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 8 Sep 2009 15:10:20 +1000 Subject: onnode: add "any" nodespec to select any node with running CTDB. In testing and other situations (e.g. eventscripts) it is necessary to select a node where a ctdb command can be run. The whole idea here is to avoid nodes where ctdbd is not running and where most ctdb commands would fail. This implements a standard way of doing this involving a recursive onnode command. There is still a small window for a race, where the selected node is suddenly shutdown, but this is unavoidable. Signed-off-by: Martin Schwenke (This used to be ctdb commit fb47cce86c0edae5caaf485f13ae7a151b6cb00d) --- ctdb/tools/onnode | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index e00cd2b1d9..79623a4a3c 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -35,7 +35,7 @@ Usage: onnode [OPTION] ... ... -p Run command in parallel on specified nodes. -q Do not print node addresses (overrides -v). -v Print node address even for a single node. - "all", "ok" (or "healthy"), "con" (or "connected"), + "all", "any", "ok" (or "healthy"), "con" (or "connected"), "rm" (or "recmaster"), "lvs" (or "lvsmaster"), "natgw" (or "natgwlist"); or a node number (0 base); or @@ -112,7 +112,7 @@ parse_nodespec () case "$i" in *-*) seq "${i%-*}" "${i#*-}" 2>/dev/null || invalid_nodespec ;; # Separate lines for readability. - all|ok|healthy|con|connected) echo "$i" ;; + all|any|ok|healthy|con|connected) echo "$i" ;; rm|recmaster|lvs|lvsmaster|natgw|natgwlist) echo "$i" ;; *) [ $i -gt -1 ] 2>/dev/null || invalid_nodespec @@ -198,6 +198,24 @@ get_node_with_property () fi } +get_any_available_node () +{ + local all_nodes="$1" + + # We do a recursive onnode to find which nodes are up and running. + local out=$($0 -pq all ctdb pnn 2>&1) + local line + while read line ; do + local pnn="${line#PNN:}" + if [ "$pnn" != "$line" ] ; then + echo_nth "$pnn" $all_nodes + return 0 + fi + # Else must be an error message from a down node. + done <<<"$out" + return 1 +} + get_nodes () { local all_nodes @@ -217,6 +235,9 @@ get_nodes () all) echo "${all_nodes//#DEAD/}" ;; + any) + get_any_available_node "$all_nodes" || exit 1 + ;; ok|healthy) get_nodes_with_status "$all_nodes" "healthy" || exit 1 ;; -- cgit From 59cacded72dc83d8cc81f840abf1801dcd361401 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 15 Sep 2009 13:35:58 +1000 Subject: try to restart statd everytime it fails, not just the first time (This used to be ctdb commit 4f7b39a4871af28df1c4545ec37db179fa47a7da) --- ctdb/tools/onnode | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 79623a4a3c..e00cd2b1d9 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -35,7 +35,7 @@ Usage: onnode [OPTION] ... ... -p Run command in parallel on specified nodes. -q Do not print node addresses (overrides -v). -v Print node address even for a single node. - "all", "any", "ok" (or "healthy"), "con" (or "connected"), + "all", "ok" (or "healthy"), "con" (or "connected"), "rm" (or "recmaster"), "lvs" (or "lvsmaster"), "natgw" (or "natgwlist"); or a node number (0 base); or @@ -112,7 +112,7 @@ parse_nodespec () case "$i" in *-*) seq "${i%-*}" "${i#*-}" 2>/dev/null || invalid_nodespec ;; # Separate lines for readability. - all|any|ok|healthy|con|connected) echo "$i" ;; + all|ok|healthy|con|connected) echo "$i" ;; rm|recmaster|lvs|lvsmaster|natgw|natgwlist) echo "$i" ;; *) [ $i -gt -1 ] 2>/dev/null || invalid_nodespec @@ -198,24 +198,6 @@ get_node_with_property () fi } -get_any_available_node () -{ - local all_nodes="$1" - - # We do a recursive onnode to find which nodes are up and running. - local out=$($0 -pq all ctdb pnn 2>&1) - local line - while read line ; do - local pnn="${line#PNN:}" - if [ "$pnn" != "$line" ] ; then - echo_nth "$pnn" $all_nodes - return 0 - fi - # Else must be an error message from a down node. - done <<<"$out" - return 1 -} - get_nodes () { local all_nodes @@ -235,9 +217,6 @@ get_nodes () all) echo "${all_nodes//#DEAD/}" ;; - any) - get_any_available_node "$all_nodes" || exit 1 - ;; ok|healthy) get_nodes_with_status "$all_nodes" "healthy" || exit 1 ;; -- cgit From 029fd6b00f8782362ec942e3b19de66233182da3 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 15 Sep 2009 19:33:35 +1000 Subject: Revert "try to restart statd everytime it fails, not just the first time" This reverts commit 4f7b39a4871af28df1c4545ec37db179fa47a7da. (This used to be ctdb commit db7b96304e4725f29b12398b7582e385daed63ed) --- ctdb/tools/onnode | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index e00cd2b1d9..79623a4a3c 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -35,7 +35,7 @@ Usage: onnode [OPTION] ... ... -p Run command in parallel on specified nodes. -q Do not print node addresses (overrides -v). -v Print node address even for a single node. - "all", "ok" (or "healthy"), "con" (or "connected"), + "all", "any", "ok" (or "healthy"), "con" (or "connected"), "rm" (or "recmaster"), "lvs" (or "lvsmaster"), "natgw" (or "natgwlist"); or a node number (0 base); or @@ -112,7 +112,7 @@ parse_nodespec () case "$i" in *-*) seq "${i%-*}" "${i#*-}" 2>/dev/null || invalid_nodespec ;; # Separate lines for readability. - all|ok|healthy|con|connected) echo "$i" ;; + all|any|ok|healthy|con|connected) echo "$i" ;; rm|recmaster|lvs|lvsmaster|natgw|natgwlist) echo "$i" ;; *) [ $i -gt -1 ] 2>/dev/null || invalid_nodespec @@ -198,6 +198,24 @@ get_node_with_property () fi } +get_any_available_node () +{ + local all_nodes="$1" + + # We do a recursive onnode to find which nodes are up and running. + local out=$($0 -pq all ctdb pnn 2>&1) + local line + while read line ; do + local pnn="${line#PNN:}" + if [ "$pnn" != "$line" ] ; then + echo_nth "$pnn" $all_nodes + return 0 + fi + # Else must be an error message from a down node. + done <<<"$out" + return 1 +} + get_nodes () { local all_nodes @@ -217,6 +235,9 @@ get_nodes () all) echo "${all_nodes//#DEAD/}" ;; + any) + get_any_available_node "$all_nodes" || exit 1 + ;; ok|healthy) get_nodes_with_status "$all_nodes" "healthy" || exit 1 ;; -- cgit From 787a6e44c62e8383855f8a1c327e1d8b414068b2 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 14 Oct 2009 13:44:57 +1100 Subject: New onnode options: -f to specify nodes file, -n to allow use of hostnames. The -f option allows an alternate nodes file to be specified, overriding the CTDB_NODES_FILE environment variable. The -n option allows hostnames to be used instead of node numbers. Using a range of hostnames is invalid, so hostnames can't contain hyphens ('-') - sorry! You can use this option without a nodes file by specifying "-f /dev/null". Signed-off-by: Martin Schwenke (This used to be ctdb commit 46474e5f21fd97dd765c616647ff46055a9970e7) --- ctdb/tools/onnode | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 79623a4a3c..7c0a86eb9d 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -34,11 +34,14 @@ Usage: onnode [OPTION] ... ... -o Save standard output from each node to file . -p Run command in parallel on specified nodes. -q Do not print node addresses (overrides -v). + -n Allow nodes to be specified by name. + -f Specify nodes file, overrides CTDB_NODES_FILE. -v Print node address even for a single node. "all", "any", "ok" (or "healthy"), "con" (or "connected"), "rm" (or "recmaster"), "lvs" (or "lvsmaster"), - "natgw" (or "natgwlist"); - or a node number (0 base); or + "natgw" (or "natgwlist"); or + a node number (0 base); or + a hostname (if -n is specified); or list (comma separated) of ; or range (hyphen separated) of node numbers. EOF @@ -58,13 +61,14 @@ parallel=false verbose=false quiet=false prefix="" +names_ok=false parse_options () { # $POSIXLY_CORRECT means that the command passed to onnode can # take options and getopt won't reorder things to make them # options ot onnode. - local temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cho:pqv" -l help -- "$@") + local temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqv" -l help -- "$@") [ $? != 0 ] && usage @@ -73,6 +77,8 @@ parse_options () while true ; do case "$1" in -c) current=true ; shift ;; + -f) CTDB_NODES_FILE="$2" ; shift 2 ;; + -n) names_ok=true ; shift ;; -o) prefix="$2" ; shift 2 ;; -p) parallel=true ; shift ;; -q) quiet=true ; shift ;; @@ -115,7 +121,7 @@ parse_nodespec () all|any|ok|healthy|con|connected) echo "$i" ;; rm|recmaster|lvs|lvsmaster|natgw|natgwlist) echo "$i" ;; *) - [ $i -gt -1 ] 2>/dev/null || invalid_nodespec + [ $i -gt -1 ] 2>/dev/null || $names_ok || invalid_nodespec echo $i esac done @@ -223,7 +229,7 @@ get_nodes () if [ -n "$CTDB_NODES_SOCKETS" ] ; then all_nodes="$CTDB_NODES_SOCKETS" else - [ -f "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes + [ -e "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes all_nodes=$(sed -e 's@#.*@@g' -e 's@ *@@g' -e 's@^$@#DEAD@' $CTDB_NODES_FILE) fi @@ -253,10 +259,13 @@ get_nodes () natgw|natgwlist) get_node_with_property "$all_nodes" "natgwlist" || exit 1 ;; - *) + [0-9]|[0-9][0-9]|[0-9][0-9][0-9]) echo_nth $n $all_nodes + ;; + *) + $names_ok || invalid_nodespec + echo $n esac - done } -- cgit From 14b3c37d9ddf3387bb30e68bd8b1ba08c789070e Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 21 Jan 2010 13:16:18 +1100 Subject: onnode - respect $CTDB_BASE rather than hard-coding /etc/ctdb. Signed-off-by: Martin Schwenke (This used to be ctdb commit a9aa2e06774e8cd59a86d3343d3da2a2769561b5) --- ctdb/tools/onnode | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 7c0a86eb9d..c44b89ad5d 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -63,6 +63,8 @@ quiet=false prefix="" names_ok=false +ctdb_base="${CTDB_BASE:-/etc/ctdb}" + parse_options () { # $POSIXLY_CORRECT means that the command passed to onnode can @@ -165,7 +167,7 @@ get_nodes_with_status () # Succeeded. Get address. NOTE: this is an optimisation. # It might be better to get the node number and then get # the nth node to get the address. This would make things - # more consistent if /etc/ctdb/nodes actually contained + # more consistent if $ctdb_base/nodes actually contained # hostnames. nodes="${nodes} ${t##*:}" fi @@ -229,7 +231,7 @@ get_nodes () if [ -n "$CTDB_NODES_SOCKETS" ] ; then all_nodes="$CTDB_NODES_SOCKETS" else - [ -e "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE=/etc/ctdb/nodes + [ -e "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE="${ctdb_base}/nodes" all_nodes=$(sed -e 's@#.*@@g' -e 's@ *@@g' -e 's@^$@#DEAD@' $CTDB_NODES_FILE) fi @@ -305,7 +307,7 @@ if [ -n "$CTDB_NODES_SOCKETS" ] ; then SSH=fakessh else # Could "2>/dev/null || true" but want to see errors from typos in file. - [ -r /etc/ctdb/onnode.conf ] && . /etc/ctdb/onnode.conf + [ -r "${ctdb_base}/onnode.conf" ] && . "${ctdb_base}/onnode.conf" [ -n "$SSH" ] || SSH=ssh if [ "$SSH" = "ssh" ] ; then ssh_opts="-n" -- cgit From 9660f9c887a27fb0fca05c5ef6e533c1e52e1e65 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 21 Jan 2010 13:40:03 +1100 Subject: onnode: update algorithm for finding nodes file. 2 changes: * If a relative nodes file is specified via -f or $CTDB_NODES_FILE but this file does not exist then try looking for the file in /etc/ctdb (or $CTDB_BASE if set). * If a nodes file is specified via -f or $CTDB_NODES_FILE but this file does not exist (even when checked as per above) then do not fall back to /etc/ctdb/nodes ((or $CTDB_BASE if set). The old behaviour was surprising and hid errors. Signed-off-by: Martin Schwenke (This used to be ctdb commit 6b5a5bb62369284585057caf09f05d2d5e3b9927) --- ctdb/tools/onnode | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index c44b89ad5d..fa61b47e5b 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -231,8 +231,21 @@ get_nodes () if [ -n "$CTDB_NODES_SOCKETS" ] ; then all_nodes="$CTDB_NODES_SOCKETS" else - [ -e "$CTDB_NODES_FILE" ] || CTDB_NODES_FILE="${ctdb_base}/nodes" - all_nodes=$(sed -e 's@#.*@@g' -e 's@ *@@g' -e 's@^$@#DEAD@' $CTDB_NODES_FILE) + local f="${ctdb_base}/nodes" + if [ -n "$CTDB_NODES_FILE" ] ; then + f="$CTDB_NODES_FILE" + if [ ! -e "$f" -a "${f#/}" = "$f" ] ; then + # $f is relative, try in $ctdb_base + f="${ctdb_base}/${f}" + fi + fi + + if [ ! -r "$f" ] ; then + echo "${prog}: unable to open nodes file \"${f}\"" >&2 + exit 1 + fi + + all_nodes=$(sed -e 's@#.*@@g' -e 's@ *@@g' -e 's@^$@#DEAD@' "$f") fi local nodes="" -- cgit From 597083d37ab6326adc17046a74858f4b0967446b Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 17 May 2011 13:18:11 +1000 Subject: onnode - Fix long standing bug in onnode healthy/ok/connected/con. When the output of "ctdb status -Y" changed to add an extra status column we didn't fix onnode. This adds a match for the extra column. Signed-off-by: Martin Schwenke (This used to be ctdb commit 793febaebd3d484ddfbbcb47aaa0cdf3cfc1a00d) --- ctdb/tools/onnode | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index fa61b47e5b..264937ea68 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -139,10 +139,10 @@ get_nodes_with_status () local bits case "$status" in healthy) - bits="0:0:0:0:0" + bits="0:0:0:0:0:0" ;; connected) - bits="0:[0-1]:[0-1]:[0-1]:[0-1]" + bits="0:[0-1]:[0-1]:[0-1]:[0-1]:[0-1]" ;; *) invalid_nodespec -- cgit From 350f3e5b09edf14a8b2ba94d8a8c1dd3329eae26 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 17 May 2011 13:20:51 +1000 Subject: onnode: Be defensive when listing IPs of nodes with designated status. The current version gives the last item left after stripping the known fields. If an insufficent number of status fields is stripped then this would return a residual status field value, which turned out to be a valid IP address for localhost... so no error occurs. This change means that the node number is stripped and any residual status field value will stay appended, causing an error the first time this command is tested. Signed-off-by: Martin Schwenke (This used to be ctdb commit 74715e6ec7b67c6f0e863aa51c87279758d6bf91) --- ctdb/tools/onnode | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 264937ea68..7e1b0cac83 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -169,7 +169,7 @@ get_nodes_with_status () # the nth node to get the address. This would make things # more consistent if $ctdb_base/nodes actually contained # hostnames. - nodes="${nodes} ${t##*:}" + nodes="${nodes} ${t#:*:}" fi done -- cgit From f3ea7bec681ca68917903882da7332756d6eafa4 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 17 May 2011 13:25:08 +1000 Subject: onnode: Exit with error for unknown command-line flags. Use of "local" was masking errors in command-line processing. Signed-off-by: Martin Schwenke (This used to be ctdb commit ca80adda7517b43147ef30156ae34c66b29fa2bd) --- ctdb/tools/onnode | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 7e1b0cac83..77a1207d6c 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -70,7 +70,9 @@ parse_options () # $POSIXLY_CORRECT means that the command passed to onnode can # take options and getopt won't reorder things to make them # options ot onnode. - local temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqv" -l help -- "$@") + local temp + # Not on the previous line - local returns 0! + temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqv" -l help -- "$@") [ $? != 0 ] && usage -- cgit From f730194f120520ddee3b6ebabbdcc49a0d98a385 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 17 May 2011 14:24:30 +1000 Subject: onnode: Future-proof get_nodes_with_status(). The current code requires knowledge of the number of status bits output by "ctdb status -Y". This changes the code to be completely general. Signed-off-by: Martin Schwenke (This used to be ctdb commit e1788f25fde3d1f26bf4831a331741aa280f6fbc) --- ctdb/tools/onnode | 57 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 77a1207d6c..9adb5caf68 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -138,18 +138,6 @@ get_nodes_with_status () local all_nodes="$1" local status="$2" - local bits - case "$status" in - healthy) - bits="0:0:0:0:0:0" - ;; - connected) - bits="0:[0-1]:[0-1]:[0-1]:[0-1]:[0-1]" - ;; - *) - invalid_nodespec - esac - if [ -z "$ctdb_status_output" ] ; then # FIXME: need to do something if $CTDB_NODES_SOCKETS is set. ctdb_status_output=$(ctdb -Y status 2>/dev/null) @@ -160,22 +148,35 @@ get_nodes_with_status () ctdb_status_output="${ctdb_status_output#* }" fi - local nodes="" - local i - for i in $ctdb_status_output ; do - # Try removing bits from end. - local t="${i%:${bits}:}" - if [ "$t" != "$i" ] ; then - # Succeeded. Get address. NOTE: this is an optimisation. - # It might be better to get the node number and then get - # the nth node to get the address. This would make things - # more consistent if $ctdb_base/nodes actually contained - # hostnames. - nodes="${nodes} ${t#:*:}" - fi - done - - echo $nodes + ( + local i + for i in $ctdb_status_output ; do + + IFS="${IFS}:" + set -- $i + shift # line starts with : so 1st field is empty + local pnn="$1" ; shift + local ip="$1" ; shift + + case "$status" in + healthy) + # If any bit is not 0, don't match this address. + local s + for s ; do + [ "$s" = "0" ] || continue 2 + done + ;; + connected) + # If disconnected bit is not 0, don't match this address. + [ "$1" = "0" ] || continue + ;; + *) + invalid_nodespec + esac + + echo_nth "$pnn" $all_nodes + done + ) } ctdb_props="" # cache -- cgit From 41436193ddcd4f83ceecbc3f23d78a9dec2875b3 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 17 May 2011 14:26:55 +1000 Subject: onnode: Remove an unnecessary comment. The comment about $CTDB_NODES_SOCKETS is meaningless. The code ti refers to works just find with $CTDB_NODES_SOCKETS. Signed-off-by: Martin Schwenke (This used to be ctdb commit 74e69a564bac653dadfffe8b08145b9b3be16e61) --- ctdb/tools/onnode | 1 - 1 file changed, 1 deletion(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 9adb5caf68..707294d5bd 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -139,7 +139,6 @@ get_nodes_with_status () local status="$2" if [ -z "$ctdb_status_output" ] ; then - # FIXME: need to do something if $CTDB_NODES_SOCKETS is set. ctdb_status_output=$(ctdb -Y status 2>/dev/null) if [ $? -ne 0 ] ; then echo "${prog}: unable to get status of CTDB nodes" >&2 -- cgit From 1ef399e48d7370fb7e4870d52f86a0878f35b1e2 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 23 May 2011 15:24:52 +1000 Subject: onnode: fix get_nodes_with_status() Setting IFS and looping though items with colons in them doesn't work. Change this to read through the output line by line. The header line needs to be thrown away by throwing away everything up to the 1st newline. Keep stderr from the "ctdb status" command, otherwise debugging is impossible. On error, append any output from ctdb to onnode's error message. Signed-off-by: Martin Schwenke (This used to be ctdb commit d60592cf99999f10344a05ef0571fb300bb9d97c) --- ctdb/tools/onnode | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 707294d5bd..59f2535d28 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -139,21 +139,24 @@ get_nodes_with_status () local status="$2" if [ -z "$ctdb_status_output" ] ; then - ctdb_status_output=$(ctdb -Y status 2>/dev/null) + ctdb_status_output=$(ctdb -Y status 2>&1) if [ $? -ne 0 ] ; then echo "${prog}: unable to get status of CTDB nodes" >&2 + echo "$ctdb_status_output" >&2 exit 1 fi - ctdb_status_output="${ctdb_status_output#* }" + local nl=" +" + ctdb_status_output="${ctdb_status_output#*${nl}}" fi ( local i - for i in $ctdb_status_output ; do + IFS="${IFS}:" + while IFS="" read i ; do - IFS="${IFS}:" - set -- $i - shift # line starts with : so 1st field is empty + set -- $i # split line on colons + shift # line starts with : so 1st field is empty local pnn="$1" ; shift local ip="$1" ; shift @@ -172,9 +175,9 @@ get_nodes_with_status () *) invalid_nodespec esac - + echo_nth "$pnn" $all_nodes - done + done <<<"$ctdb_status_output" ) } -- cgit From 5ddc10128aaa78d4de85eda4b54f173b4cc88d39 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 23 May 2011 15:33:12 +1000 Subject: onnode: fix natgwlist nodespec This hasn't worked for a while if ever. We treat this case specially because the output has 2 works on the 1st line. We also handle the error case where /etc/ctdb_natgw_nodes exists but none of the other $NATGW_* configuration is done. Signed-off-by: Martin Schwenke (This used to be ctdb commit 66e89797c7866d207a5bbf1836f52d70dba7cea6) --- ctdb/tools/onnode | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 59f2535d28..804ab09cc2 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -189,20 +189,36 @@ get_node_with_property () local prop_node="" if [ "${ctdb_props##:${prop}:}" = "$ctdb_props" ] ; then + # Not in cache. prop_node=$(ctdb "$prop" -Y 2>/dev/null) - # We only want the first line. - local nl=" -" - prop_node="${prop_node%%${nl}*}" if [ $? -eq 0 ] ; then - ctdb_props="${ctdb_props}${ctdb_props:+ }:${prop}:${prop_node}" + if [ "$prop" = "natgwlist" ] ; then + prop_node="${prop_node%% *}" # 1st word + if [ "$prop_node" = "-1" ] ; then + # This works around natgwlist returning 0 even + # when there's no natgw. + prop_node="" + fi + else + # We only want the first line. + local nl=" +" + prop_node="${prop_node%%${nl}*}" + fi else prop_node="" fi + + if [ -n "$prop_node" ] ; then + # Add to cache. + ctdb_props="${ctdb_props}${ctdb_props:+ }:${prop}:${prop_node}" + fi else + # Get from cache. prop_node="${ctdb_props##:${prop}:}" prop_node="${prop_node%% *}" fi + if [ -n "$prop_node" ] ; then echo_nth "$prop_node" $all_nodes else -- cgit From 2e3febe283f5d6f24a2527d0e221eb46d1ca3c22 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 7 Oct 2011 14:59:46 +1100 Subject: onnode: unset EXTRA_SSH_OPTS when using fakessh This case was never tested and fakessh obviously won't handle the extra arguments. Signed-off-by: Martin Schwenke (This used to be ctdb commit 02184bd5b9ab94cdf2b9ff92e56a509f92f9e4aa) --- ctdb/tools/onnode | 1 + 1 file changed, 1 insertion(+) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 804ab09cc2..4bd8243153 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -339,6 +339,7 @@ $current && command="cd $PWD && $command" ssh_opts= if [ -n "$CTDB_NODES_SOCKETS" ] ; then SSH=fakessh + EXTRA_SSH_OPTS="" else # Could "2>/dev/null || true" but want to see errors from typos in file. [ -r "${ctdb_base}/onnode.conf" ] && . "${ctdb_base}/onnode.conf" -- cgit From f53b4f82f51ba89b04dfae26c6c9bd11a8e19495 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 17 Jul 2012 16:45:55 +1000 Subject: tools/onnode: Add -P option to push files to given nodes A list of files is given rather than a command. These files are pushed to the specified nodes. Quoting is fragile/broken so filenames with spaces won't work - you win some, you lose some. :-) All of the other onnode options should work together with this option. Signed-off-by: Martin Schwenke (This used to be ctdb commit aed9b98ddbbf3e81de4f7257a10676565f7d7507) --- ctdb/tools/onnode | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 4bd8243153..11ad708693 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -37,6 +37,7 @@ Usage: onnode [OPTION] ... ... -n Allow nodes to be specified by name. -f Specify nodes file, overrides CTDB_NODES_FILE. -v Print node address even for a single node. + -P Push given files to nodes instead of running commands. "all", "any", "ok" (or "healthy"), "con" (or "connected"), "rm" (or "recmaster"), "lvs" (or "lvsmaster"), "natgw" (or "natgwlist"); or @@ -62,6 +63,7 @@ verbose=false quiet=false prefix="" names_ok=false +push=false ctdb_base="${CTDB_BASE:-/etc/ctdb}" @@ -72,7 +74,7 @@ parse_options () # options ot onnode. local temp # Not on the previous line - local returns 0! - temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqv" -l help -- "$@") + temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cf:hno:pqvP" -l help -- "$@") [ $? != 0 ] && usage @@ -87,6 +89,7 @@ parse_options () -p) parallel=true ; shift ;; -q) quiet=true ; shift ;; -v) verbose=true ; shift ;; + -P) push=true ; shift ;; --) shift ; break ;; -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable. esac @@ -305,6 +308,21 @@ get_nodes () done } +push() +{ + local host="$1" + local files="$2" + + local f + for f in $files ; do + $verbose && echo "Pushing $f" + case "$f" in + /*) rsync "$f" "${host}:${f}" ;; + *) rsync "${PWD}/${f}" "${host}:${PWD}/${f}" ;; + esac + done +} + fakessh () { CTDB_SOCKET="$1" sh -c "$2" 3>/dev/null @@ -334,20 +352,25 @@ stderr_filter () parse_options "$@" -$current && command="cd $PWD && $command" - ssh_opts= -if [ -n "$CTDB_NODES_SOCKETS" ] ; then - SSH=fakessh +if $push ; then + SSH=push EXTRA_SSH_OPTS="" -else - # Could "2>/dev/null || true" but want to see errors from typos in file. - [ -r "${ctdb_base}/onnode.conf" ] && . "${ctdb_base}/onnode.conf" - [ -n "$SSH" ] || SSH=ssh - if [ "$SSH" = "ssh" ] ; then - ssh_opts="-n" - else - : # rsh? All bets are off! +else + $current && command="cd $PWD && $command" + + if [ -n "$CTDB_NODES_SOCKETS" ] ; then + SSH=fakessh + EXTRA_SSH_OPTS="" + else + # Could "2>/dev/null || true" but want to see errors from typos in file. + [ -r "${ctdb_base}/onnode.conf" ] && . "${ctdb_base}/onnode.conf" + [ -n "$SSH" ] || SSH=ssh + if [ "$SSH" = "ssh" ] ; then + ssh_opts="-n" + else + : # rsh? All bets are off! + fi fi fi -- cgit From e8de58abd7fe7bec7752c6e33ea3e366d3c31a9d Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 24 Oct 2013 14:15:53 +1100 Subject: tools/onnode: Fix healthy/ok node handling This bit-rotted a long time ago when the "ThisNode" column was added to "ctdb -Y status" output. The fake "ctdb -Y status" output in the test was never updated to reflect this change. Instead of making sure that all columns are "0", just check that they're not "1". This implicitly ignores "Y" and "N" in this "ThisNode" column without having to do anything else clever. Also update associated tests. The main "ctdb ok" test had a duplicate opening line for a here document, which was tickled by this change. This fixes samba bz#8122. Signed-off-by: Martin Schwenke onnode test fixup Signed-off-by: Martin Schwenke (This used to be ctdb commit 01a46205c3a3d6609dc0b0324319b89667dffa32) --- ctdb/tools/onnode | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ctdb/tools/onnode') diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode index 11ad708693..0abc13636e 100755 --- a/ctdb/tools/onnode +++ b/ctdb/tools/onnode @@ -165,10 +165,10 @@ get_nodes_with_status () case "$status" in healthy) - # If any bit is not 0, don't match this address. + # If any bit is 1, don't match this address. local s for s ; do - [ "$s" = "0" ] || continue 2 + [ "$s" != "1" ] || continue 2 done ;; connected) -- cgit