summaryrefslogtreecommitdiff
path: root/ctdb/tools/onnode
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2008-09-12 16:55:18 +1000
committerMartin Schwenke <martin@meltin.net>2008-09-12 16:55:18 +1000
commit62a65ebc38cace60a0af74e29c43e52bb20c75cc (patch)
treefce2e002bcc26ac32dd6d469721bad994bcf1d85 /ctdb/tools/onnode
parent0013ec94de40491626a0d74962a56596adf8b839 (diff)
downloadsamba-62a65ebc38cace60a0af74e29c43e52bb20c75cc.tar.gz
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 <martin@meltin.net> (This used to be ctdb commit 05bdafed82106a0d8bfa53cd730eb3e1db68a51f)
Diffstat (limited to 'ctdb/tools/onnode')
-rwxr-xr-xctdb/tools/onnode48
1 files changed, 36 insertions, 12 deletions
diff --git a/ctdb/tools/onnode b/ctdb/tools/onnode
index c60127ce090..6fb8fbe7bc7 100755
--- a/ctdb/tools/onnode
+++ b/ctdb/tools/onnode
@@ -34,7 +34,8 @@ Usage: onnode [OPTION] ... <NODES> <COMMAND> ...
-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.
- <NODES> "all", "healthy", "connected";
+ <NODES> "all", "ok" (or "healthy"), "con" (or "connected"),
+ "rm" (or "recmaster");
or a node number (0 base); or
list (comma separated) of <NODES>; 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