3 if [ -z "$CTDB_BASE" ] ; then
4 export CTDB_BASE
="/usr/local/etc/ctdb"
7 .
"${CTDB_BASE}/functions"
9 load_script_options
"failover" "91.lvs"
11 # Default LVS nodes file location
12 [ -n "$CTDB_LVS_NODES" ] || CTDB_LVS_NODES
="${CTDB_BASE}/lvs_nodes"
14 if [ -z "$CTDB" ] ; then
18 ############################################################
26 leader Display node number of leader node
27 list List node number and private IP address of usable nodes in group
28 status Show status of all nodes in LVS group
35 # Node|IP|Disconnected|Unknown|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode
38 # Result is cached in global variable nodestatus_X
39 [ -n "$nodestatus_X" ] || \
40 nodestatus_X
=$
($CTDB -X nodestatus all |
41 sed -e '1d' -e 's@^|@@' -e 's@|$@@')
46 # Result is cached in global variable nodestatus
47 [ -n "$nodestatus" ] || nodestatus
=$
($CTDB nodestatus all
)
49 # $CTDB nodestatus returns 255 on failure
57 # Result is cached in global variable lvs_nodes
58 if [ -n "$lvs_nodes" ] ; then
62 if [ ! -r "$CTDB_LVS_NODES" ] ; then
66 lvs_nodes
=$
(cat "$CTDB_LVS_NODES") ||
return 1
68 # Sanity check file contents here
69 while read _ip _options
; do
75 follower-only|
"") : ;;
76 *) die
"${prog}: Invalid options \"${_options}\" in \"$CTDB_LVS_NODES\""
85 # Print PNN and IP address of given nodes meeting the criteria for
86 # usable LVS nodes. That is, either those that are healthy or, if no
87 # healthy nodes, then nodes that are active and not-disabled.
88 # Return codes: 0 = nodes found, 255 = no nodes found, 10 = error.
91 # $_ns is an @-delimited list of nodes to be considered
95 [ -n "$nodestatus_X" ] ||
return 10
97 # Now filter by $_ns and by status of nodes...
99 # Note that the 2 awk invocations below have "||" between
100 # them, so the first to succeed will print the nodes.
102 # First try for a fully active and healthy node, so must not
103 # be UNKNOWN, DISABLED, UNHEALTHY or INACTIVE (last covers
104 # DISCONNECTED, BANNED or STOPPED)
105 awk -F '|' -v ns
="$_ns" '
107 ns ~ "@" $2 "@" && $4 == 0 && $6 == 0 && $7 == 0 && $9 == 0 {
114 # Not found? UNHEALTHY do, so node must not be INACTIVE or
116 awk -F '|' -v ns
="$_ns" '
118 ns ~ "@" $2 "@" && $6 == 0 && $9 == 0 {
127 # Print the PNN of the LVS leader node
131 die
"${prog}: LVS nodes file \"$CTDB_LVS_NODES\" not found"
133 # $_ms is an @-delimited list of nodes that are allowed to be the leader
135 while read _ip _options
; do
137 "") _ms
="${_ms}${_ip}@" ;;
143 _leader_candidates
=$
(filter_nodes
"$_ms") ||
return $?
144 echo "${_leader_candidates%% *}"
147 # List all usable nodes in the LVS group
151 die
"${prog}: LVS nodes file \"$CTDB_LVS_NODES\" not found"
153 # $_ns is a @-delimited list of nodes in the LVS group
155 while read _ip _options
; do
161 _usable_nodes
=$
(filter_nodes
"$_ns")
164 255) exit 0 ;; # Return 0 even if no usable nodes
168 awk '{ print $1, $2 }'<<EOF
173 # Print the status of all nodes in the LVS group, along with a count
177 die
"${prog}: LVS nodes file \"$CTDB_LVS_NODES\" not found"
179 [ -n "$nodestatus" ] ||
exit 10
181 # $_ns is a @-delimited list of nodes in the LVS group
183 while read _ip _options
; do
189 # Print status of nodes in $_ns, along with node count
190 awk -v ns
="$_ns" 'ns ~ "@" $2 "@" { print }' <<EOF
195 # For backward compatibility
196 prog
=$
(basename "$0")
200 leader
) find_leader
;;
202 status
) nodes_status
;;