3 if [ -z "$CTDB_BASE" ] ; then
4 export CTDB_BASE
="/usr/local/etc/ctdb"
7 .
"${CTDB_BASE}/functions"
10 # Default NAT gateway nodes file location
11 [ -n "$CTDB_NATGW_NODES" ] || CTDB_NATGW_NODES
="${CTDB_BASE}/natgw_nodes"
13 [ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
15 if [ -z "$CTDB" ] ; then
19 ############################################################
27 master Display node number and private IP address of master node
28 list List private IP addresses of nodes in group, annotate master
29 status Show status of nodes in NAT gateway 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
)
49 [ $?
-ne 255 ] # ctdb nodestatus returns 255 on failure
54 # Result is cached in global variable natgw_nodes
55 if [ -n "$natgw_nodes" ] ; then
59 if [ ! -r "$CTDB_NATGW_NODES" ] ; then
63 natgw_nodes
=$
(cat "$CTDB_NATGW_NODES") ||
return 1
65 # Sanity check file contents here
66 while read _ip _options
; do
73 *) die
"${prog}: Invalid options \"${_options}\" in \"$CTDB_NATGW_NODES\""
82 # Print the PNN and IP address of the NAT gateway master node
86 die
"${prog}: NAT gateway nodes file \"$CTDB_NATGW_NODES\" not found"
88 die
"${prog}: Unable to get status of nodes"
90 # $_ms is an @-delimited list of nodes that are allowed to be the master
92 while read _ip _options
; do
94 "") _ms
="${_ms}${_ip}@" ;;
100 # Now filter by $ms and by status of nodes...
102 # Note that the 3 awk invocations below have "||" between them, so
103 # the first to succeed will select the master node.
105 # First try for a fully active and healthy node, so must not be
106 # DISABLED, UNHEALTHY or INACTIVE (last covers DISCONNECTED,
108 awk -F '|' -v ms
="$_ms" \
111 $5 == 0 && $6 == 0 && $8 == 0 { print $1, $2 ; ret=0 ; exit }
112 END { exit ret }' <<EOF ||
115 # Not found? UNHEALTHY/BANNED will do, so node must not be
116 # DISCONNECTED, DISABLED or STOPPED
117 awk -F '|' -v ms
="$_ms" \
120 $3 == 0 && $5 == 0 && $7 == 0 { print $1, $2 ; ret=0 ; exit }
121 END { exit ret }' <<EOF ||
124 # Not found? STOPPED will do, so node must not be DISCONNECTED or
126 awk -F '|' -v ms
="$_ms" \
129 $3 == 0 && $5 == 0 { print $1, $2 ; ret=0 ; exit }
130 END { exit ret }' <<EOF
135 # List all nodes in the NAT gateway group, annotating the master node
139 die
"${prog}: NAT gateway nodes file \"$CTDB_NATGW_NODES\" not found"
140 # Intentional word splitting here
141 # shellcheck disable=SC2046
142 set -- $
(find_master
) || \
143 die
"${prog}: Unable to determine NAT gateway master node"
146 # Annotate the master node
147 while read _ip _options
; do
148 if [ "$_ip" = "$_master_ip" ] ; then
149 _options
="MASTER${_options:+,}${_options}"
151 # There is no other way to do this and keep shellcheck happy.
152 # The tab character must be in the format string and the
153 # format string must contain no variables. Some shells will
154 # expand a tab if it is in an argument but others won't.
155 if [ -n "$_options" ] ; then
156 printf "%s\t%s\n" "$_ip" "$_options"
165 # Print the status of all nodes in the NAT gateway group, along with a count
169 die
"${prog}: NAT gateway nodes file \"$CTDB_NATGW_NODES\" not found"
171 die
"${prog}: Unable to get status of nodes"
173 # $_ns is a @-delimited list of nodes in the NAT gateway group
175 while read _ip _options
; do
181 # Print status of nodes in $_ns, along with node count
182 awk -v ns
="$_ns" 'ns ~ "@" $2 "@" { print $0 }' <<EOF
187 prog
=$
(basename "$0")
191 master
) find_master
;;
193 status
) nodes_status
;;