From b8003bee7c0ba48094bd13b3fa49b59022aaebcd Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sun, 14 May 2023 10:02:48 -0500 Subject: [PATCH] update --- defaults.inc | 2 +- nodemgmt-scripts.sh | 54 +++++++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/defaults.inc b/defaults.inc index 61996322..c1e4bc2f 100755 --- a/defaults.inc +++ b/defaults.inc @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERS='4.6.50-05132023' +VERS='4.6.55-05132023' # NODETYPES=LB NODETYPES=MYSQL,LB,WEB,NC,WPD,LPD,MM,PW diff --git a/nodemgmt-scripts.sh b/nodemgmt-scripts.sh index d7dee056..05c5448e 100755 --- a/nodemgmt-scripts.sh +++ b/nodemgmt-scripts.sh @@ -360,13 +360,16 @@ SERVICES(){ } SERVICE(){ + TSI=$(/sbin/ip link | grep tailscale0) + MIP=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) + [ ${#TSI} != 0 ] && TSIP=$(/sbin/ip -o -4 addr list tailscale0 | awk '{print $4}' | cut -d/ -f1) || TSIP="" NODE_TYPE='' #var=NC_HOSTS[@] if [ "$1" = "glusterd" ]; then for nip in "${GL_HOSTS[@]}"; do - if [[ $(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) == *"${nip}"* ]]; then + if [[ "${MIP}" == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -402,7 +405,7 @@ SERVICE(){ sleep 5s for nip in "${GL_HOSTS[@]}"; do - if [[ $(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) == *"${nip}"* ]]; then + if [[ "${MIP}" == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -450,42 +453,29 @@ SERVICE(){ else if [ "${4}" != "all" ]; then - IP=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) - echo "IP: ${IP}" for NTYPE in "${NODE_TYPES[@]}"; do var=${NTYPE}_HOSTS[@] NODE_TYPE="" for nip in "${!var}"; do - echo "$IP - $nip" - if [[ "${IP}" == *"${nip}"* ]]; then + if [[ "${MIP}" == *"${nip}"* ]]; then NODE_TYPE=${NTYPE}; break 2 fi done done - - echo "NODETYPE: ${NODE_TYPE}" - - if [ "${NODE_TYPE}" == "" ]; then - TSI=$(/sbin/ip link | grep tailscale0) - TSIP=$(/sbin/ip -o -4 addr list tailscale0 | awk '{print $4}' | cut -d/ -f1) - echo "TSIP: ${TSIP}" - if [ ${#TSI} != 0 ]; then - for NTYPE in "${NODE_TYPES[@]}"; do - var=${NTYPE}_HOSTS[@] - for nip in "${!var}"; do - echo "${TSIP} - $nip" - if [[ "${TSIP}" == *"${nip}"* ]]; then - NODE_TYPE=${NTYPE}; - break 2 - fi - done + + if [ "${NODE_TYPE}" == "" ] && [ ${#TSI} != 0 ]; then + for NTYPE in "${NODE_TYPES[@]}"; do + var=${NTYPE}_HOSTS[@] + for nip in "${!var}"; do + if [[ "${TSIP}" == *"${nip}"* ]]; then + NODE_TYPE=${NTYPE}; + break 2 + fi done - fi + done fi - - echo "NODETYPE: ${NODE_TYPE}" - + if [ "${NODE_TYPE}" != "" ]; then NT_HOSTS=${NODE_TYPE}_HOSTS[@] NT_HOST=${NODE_TYPE}_HOSTS[0] @@ -525,7 +515,7 @@ SERVICE(){ if [ "${3}" != "q" ]; then echo -en "${idsCL[LightYellow]}Verifying nginx config and ssl cert replication across the nodes... ${idsCL[Default]}" fi - if [[ $(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) == *"${!NT_HOST}"* ]]; then + if [[ "${MIP}" == *"${!NT_HOST}"* ]]; then PH_CMD="ssh root@localhost" else PH_CMD="ssh root@${!NT_HOST}" @@ -559,7 +549,7 @@ SERVICE(){ if [ "${3}" != "q" ]; then echo -en "${idsCL[LightYellow]}Verifying Apache config and ssl cert replication across the nodes... ${idsCL[Default]}" fi - if [[ $(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) == *"${!NT_HOST}"* ]]; then + if [[ "${MIP}" == *"${!NT_HOST}"* ]]; then PH_CMD="ssh root@localhost" else PH_CMD="ssh root@${!NT_HOST}" @@ -603,7 +593,9 @@ SERVICE(){ fi for nip in "${var2[@]}"; do - # if [[ $(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) == *"${3}"* ]]; then GO=true; + + + # if [[ "${MIP}" == *"${3}"* ]]; then GO=true; # elif [ ! -z ${3+x} ] || [ "${3}" == "q" ]; then GO=true; # else GO=false; # fi @@ -613,7 +605,7 @@ SERVICE(){ else nodename="${NM_NODETYPES[$NTYPE]}-Node${nid}" fi - if [[ $(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) == *"${nip}"* ]]; then + if [[ "${MIP}" == *"${nip}"* ]]; then nip='localhost ' NCMD='' else