3 if [ -z "$CTDB_BASE" ] ; then
4 export CTDB_BASE
="/usr/local/etc/ctdb"
7 .
"${CTDB_BASE}/functions"
10 # Default LVS nodes file location
11 [ -n "$CTDB_LVS_NODES" ] || CTDB_LVS_NODES
="${CTDB_BASE}/lvs_nodes"
13 [ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
15 if [ -z "$CTDB" ] ; then
19 ############################################################
27 master Display node number of master node
28 list List node number and private IP address of usable nodes in group
29 status Show status of all nodes in LVS group
36 # Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode
39 # Result is cached in global variable nodestatus_X
40 [ -n "$nodestatus_X" ] || \
41 nodestatus_X
=$
($CTDB -X nodestatus all |
42 sed -e '1d' -e 's@^|@@' -e 's@|$@@')
47 # Result is cached in global variable nodestatus
48 [ -n "$nodestatus" ] || nodestatus
=$
($CTDB nodestatus all
)
50 # $CTDB nodestatus returns 255 on failure
58 # Result is cached in global variable lvs_nodes
59 if [ -n "$lvs_nodes" ] ; then
63 if [ ! -r "$CTDB_LVS_NODES" ] ; then
67 lvs_nodes
=$
(cat "$CTDB_LVS_NODES") ||
return 1
69 # Sanity check file contents here
70 while read _ip _options
; do
77 *) die
"${prog}: Invalid options \"${_options}\" in \"$CTDB_LVS_NODES\""
86 # Print PNN and IP address of given nodes meeting the criteria for
87 # usable LVS nodes. That is, either those that are healthy or, if no
88 # healthy nodes, then nodes that are active and not-disabled.
89 # Return codes: 0 = nodes found, 255 = no nodes found, 10 = error.
92 # $_ns is an @-delimited list of nodes to be considered
96 [ -n "$nodestatus_X" ] ||
return 10
98 # Now filter by $_ns and by status of nodes...
100 # Note that the 2 awk invocations below have "||" between
101 # them, so the first to succeed will print the nodes.
103 # First try for a fully active and healthy node, so must not
104 # be DISABLED, UNHEALTHY or INACTIVE (last covers
105 # DISCONNECTED, BANNED or STOPPED)
106 awk -F '|' -v ns
="$_ns" '
108 ns ~ "@" $2 "@" && $5 == 0 && $6 == 0 && $8 == 0 {
115 # Not found? UNHEALTHY do, so node must not be INACTIVE or
117 awk -F '|' -v ns
="$_ns" '
119 ns ~ "@" $2 "@" && $5 == 0 && $8 == 0 {
128 # Print the PNN of the LVS master node
132 die
"${prog}: LVS nodes file \"$CTDB_LVS_NODES\" not found"
134 # $_ms is an @-delimited list of nodes that are allowed to be the master
136 while read _ip _options
; do
138 "") _ms
="${_ms}${_ip}@" ;;
144 _master_candidates
=$
(filter_nodes
"$_ms") ||
return $?
145 echo "${_master_candidates%% *}"
148 # List all usable nodes in the LVS group
152 die
"${prog}: LVS nodes file \"$CTDB_LVS_NODES\" not found"
154 # $_ns is a @-delimited list of nodes in the LVS group
156 while read _ip _options
; do
162 _usable_nodes
=$
(filter_nodes
"$_ns")
165 255) exit 0 ;; # Return 0 even if no usable nodes
169 awk '{ print $1, $2 }'<<EOF
174 # Print the status of all nodes in the LVS group, along with a count
178 die
"${prog}: LVS nodes file \"$CTDB_LVS_NODES\" not found"
180 [ -n "$nodestatus" ] ||
exit 10
182 # $_ns is a @-delimited list of nodes in the LVS group
184 while read _ip _options
; do
190 # Print status of nodes in $_ns, along with node count
191 awk -v ns
="$_ns" 'ns ~ "@" $2 "@" { print }' <<EOF
196 # For backward compatibility
197 prog
=$
(basename "$0")
201 master
) find_master
;;
203 status
) nodes_status
;;