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 ############################################################
23 master Display node number and private IP address of master node
24 list List private IP addresses of nodes in group, annotate master
25 status Show status of nodes in NAT gateway group
26 natgwlist Combination of "master" and "status", for backward compatiblity
33 # Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode
36 # Result is cached in global variable nodestatus_X
37 [ -n "$nodestatus_X" ] || \
38 nodestatus_X=$(ctdb -X nodestatus all |
39 sed -e '1d' -e 's@^|@@' -e 's@|$@@')
44 # Result is cached in global variable nodestatus
45 [ -n "$nodestatus" ] || nodestatus=$(ctdb nodestatus all)
46 [ $? -ne 255 ] # ctdb nodestatus returns 255 on failure
51 # Result is cached in global variable natgw_nodes
52 if [ -n "$natgw_nodes" ] ; then
56 if [ ! -r "$CTDB_NATGW_NODES" ] ; then
60 natgw_nodes=$(cat "$CTDB_NATGW_NODES") || return 1
62 # Sanity check file contents here
63 while read _ip _options ; do
70 *) die "${prog}: Invalid options \"${_options}\" in \"$CTDB_NATGW_NODES\""
79 # Print the PNN and IP address of the NAT gateway master node
83 die "${prog}: NAT gateway nodes file \"$CTDB_NATGW_NODES\" not found"
85 die "${prog}: Unable to get status of nodes"
87 # $_ms is an @-delimited list of nodes that are allowed to be the master
89 while read _ip _options ; do
91 "") _ms="${_ms}${_ip}@" ;;
97 # Now filter by $ms and by status of nodes...
99 # Note that the 3 awk invocations below have "||" between them, so
100 # the first to succeed will select the master node.
102 # First try for a fully active and healthy node, so must not be
103 # DISABLED, UNHEALTHY or INACTIVE (last covers DISCONNECTED,
105 awk -F '|' -v ms="$_ms" \
108 $5 == 0 && $6 == 0 && $8 == 0 { print $1, $2 ; ret=0 ; exit }
109 END { exit ret }' <<EOF ||
112 # Not found? UNHEALTHY/BANNED will do, so node must not be
113 # DISCONNECTED, DISABLED or STOPPED
114 awk -F '|' -v ms="$_ms" \
117 $3 == 0 && $5 == 0 && $7 == 0 { print $1, $2 ; ret=0 ; exit }
118 END { exit ret }' <<EOF ||
121 # Not found? STOPPED will do, so node must not be DISCONNECTED or
123 awk -F '|' -v ms="$_ms" \
126 $3 == 0 && $5 == 0 { print $1, $2 ; ret=0 ; exit }
127 END { exit ret }' <<EOF
132 # List all nodes in the NAT gateway group, annotating the master node
136 die "${prog}: NAT gateway nodes file \"$CTDB_NATGW_NODES\" not found"
137 set -- $(find_master) || \
138 die "${prog}: Unable to determine NAT gateway master node"
141 # Annotate the master node
142 while read _ip _options ; do
143 if [ "$_ip" = "$_master_ip" ] ; then
144 _options="MASTER${_options:+,}${_options}"
146 printf "${_ip}${_options:+\t}${_options}\n"
152 # Print the status of all nodes in the NAT gateway group, along with a count
156 die "${prog}: NAT gateway nodes file \"$CTDB_NATGW_NODES\" not found"
158 die "${prog}: Unable to get status of nodes"
160 # $_ns is a @-delimited list of nodes in the NAT gateway group
162 while read _ip _options ; do
168 # Print status of nodes in $_ns, along with node count
169 awk -v ns="$_ns" 'ns ~ "@" $2 "@" { print $0 }' <<EOF
174 # For backward compatibility
179 if [ $? -eq 2 ] ; then
183 _t=$(nodes_status) || return $?
184 _n=$(echo "$_t" | wc -l)
185 echo "Number of nodes:${_n}"
190 prog=$(basename "$0")
194 master) find_master ;;
196 status) nodes_status ;;
197 natgwlist) natgwlist ;;