From: Vinit Agnihotri Date: Tue, 30 Jan 2024 09:25:37 +0000 (-0800) Subject: ctdb-scripts: Rename and relocate function get_all_interfaces() X-Git-Url: http://git.samba.org/?p=samba.git;a=commitdiff_plain;h=56eeb058d2d5fde17c461afe7fac2f0832993a8c ctdb-scripts: Rename and relocate function get_all_interfaces() get_all_interfaces() functions gets all names for all public interfaces. However name is misleading. Thus renamed it to get_public_ifaces() and moved it under functions. Signed-off-by: Vinit Agnihotri Reviewed-by: Martin Schwenke Reviewed-by: Andrew Bartlett --- diff --git a/ctdb/config/events/legacy/10.interface.script b/ctdb/config/events/legacy/10.interface.script index fead88c014f..110b1213966 100755 --- a/ctdb/config/events/legacy/10.interface.script +++ b/ctdb/config/events/legacy/10.interface.script @@ -12,37 +12,16 @@ load_script_options -ctdb_public_addresses="${CTDB_BASE}/public_addresses" - -if [ ! -f "$ctdb_public_addresses" ]; then +if ! have_public_addresses; then if [ "$1" = "init" ] ; then echo "No public addresses file found" fi exit 0 fi -# This sets $all_interfaces as a side-effect. -get_all_interfaces () -{ - # Get all the interfaces listed in the public_addresses file - all_interfaces=$(sed -e '/^#.*/d' \ - -e 's/^[^\t ]*[\t ]*//' \ - -e 's/,/ /g' \ - -e 's/[\t ]*$//' "$ctdb_public_addresses") - - # Get the interfaces for which CTDB has public IPs configured. - # That is, for all but the 1st line, get the 1st field. - ctdb_ifaces=$($CTDB -X ifaces | sed -e '1d' -e 's@^|@@' -e 's@|.*@@') - - # Add $ctdb_ifaces and make $all_interfaces unique - # Use word splitting to squash whitespace - # shellcheck disable=SC2086 - all_interfaces=$(echo $all_interfaces $ctdb_ifaces | tr ' ' '\n' | sort -u) -} - monitor_interfaces() { - get_all_interfaces + get_public_ifaces down_interfaces_found=false up_interfaces_found=false @@ -50,7 +29,10 @@ monitor_interfaces() # Note that this loop must not exit early. It must process # all interfaces so that the correct state for each interface # is set in CTDB using setifacelink. - for _iface in $all_interfaces ; do + # + # public_ifaces set by get_public_ifaces() above + # shellcheck disable=SC2154 + for _iface in $public_ifaces ; do if interface_monitor "$_iface" ; then up_interfaces_found=true $CTDB setifacelink "$_iface" up >/dev/null 2>&1 diff --git a/ctdb/config/functions b/ctdb/config/functions index a40b276e2b8..e76082b7cb3 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -651,6 +651,30 @@ drop_ip() fi } +have_public_addresses() +{ + [ -f "${CTDB_BASE}/public_addresses" ] +} + +# This sets $public_ifaces as a side-effect. +get_public_ifaces() +{ + # Get all the interfaces listed in the public_addresses file + public_ifaces=$(sed -e '/^#.*/d' \ + -e 's/^[^\t ]*[\t ]*//' \ + -e 's/,/ /g' \ + -e 's/[\t ]*$//' "${CTDB_BASE}/public_addresses") + + # Get the interfaces for which CTDB has public IPs configured. + # That is, for all but the 1st line, get the 1st field. + ctdb_ifaces=$($CTDB -X ifaces | sed -e '1d' -e 's@^|@@' -e 's@|.*@@') + + # Add $ctdb_ifaces and make $public_ifaces unique + # Use word splitting to squash whitespace + # shellcheck disable=SC2086 + public_ifaces=$(echo $public_ifaces $ctdb_ifaces | tr ' ' '\n' | sort -u) +} + drop_all_public_ips() { # _x is intentionally ignored