From 49548389464da60a33ad01f0423388f2bb5d759a Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Tue, 4 Jul 2023 17:28:01 -0500 Subject: [PATCH] update --- defaults.inc | 13 +++---- inc/sites.inc | 13 +------ nodemgmt-scripts.sh | 87 ++++++++++++++++----------------------------- 3 files changed, 36 insertions(+), 77 deletions(-) diff --git a/defaults.inc b/defaults.inc index 145db36d..fe446b4d 100755 --- a/defaults.inc +++ b/defaults.inc @@ -1,5 +1,5 @@ -VERS='4.8.11-07042023' +VERS='4.8.15-07042023' noheader=' service status-check nightlyrephp7.3-fpm,new backup report check checkcerts gitea update-nodes copynpmcerts singleservercheck update-dyndns ' CERT_DAEMON='/snap/bin/certbot' @@ -109,8 +109,8 @@ if [ -f ${NM_FOLDER}/defaults.local.inc ]; then fi TSI=$(/sbin/ip link | grep tailscale0) -[ ${#TSI} != 0 ] && TSIP=$(/sbin/ip -o -4 addr list tailscale0 | awk '{print $4}' | cut -d/ -f1) || TSIP= -RNIP=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) +[ ${#TSI} != 0 ] && RUN_NODE_TSIP=$(/sbin/ip -o -4 addr list tailscale0 | awk '{print $4}' | cut -d/ -f1) || RUN_NODE_TSIP= +RNIP=${RUN_NODE_IP} for NTYPE in "${NM_NODE_TYPES[@]}"; do var=${NTYPE}_HOSTS[@] RUN_NODE_TYPE="" @@ -119,17 +119,14 @@ for NTYPE in "${NM_NODE_TYPES[@]}"; do RUN_NODE_TYPE=${NTYPE}; RUN_NODE_IP=${RNIP} break 2 - elif [[ "${TSIP}" == *"${nip}"* ]]; then + elif [[ "${RUN_NODE_TSIP}" == *"${nip}"* ]]; then RUN_NODE_TYPE=${NTYPE}; - RUN_NODE_IP=${TSIP} + RUN_NODE_IP=${RUN_NODE_TSIP} break 2 fi done done -echo "RUN_NODE_IP: $RUN_NODE_IP" -echo "RUN_NODE_TYPE: $RUN_NODE_TYPE" - declare -A NM_SRVCOPTS NM_SRVCOPTS['status']='Status' NM_SRVCOPTS['start']='Start' diff --git a/inc/sites.inc b/inc/sites.inc index 71e87944..8a7909f4 100755 --- a/inc/sites.inc +++ b/inc/sites.inc @@ -510,17 +510,6 @@ SITEINFO(){ cw_spc6=8 cw_spc7=15 dl=110 - MIP=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) - for NTYPE in "${NM_NODE_TYPES[@]}"; do - var=${NTYPE}_HOSTS[@] - NODE_TYPE="" - for nip in "${!var}"; do - if [[ "${MIP}" == *"${nip}"* ]]; then - NODE_TYPE=${NTYPE}; - break 2 - fi - done - done if [ "${1}" == "edit" ]; then [ "${2}" == "" ] && echo -e "${idsCL[LightGreen]}Choose a site from the list below to edit: ${idsCL[Default]}" @@ -528,7 +517,7 @@ SITEINFO(){ echo -e "${idsCL[LightGreen]}Local NGINX Sites ${idsCL[Default]}" fi - gosite=${NODE_TYPE}_NGINX_SITES + gosite=${RUN_NODE_TYPE}_NGINX_SITES declare -A SITELIST if [ "${!gosite}" != "" ]; then sites=$(find ${!gosite}/*); i=0 diff --git a/nodemgmt-scripts.sh b/nodemgmt-scripts.sh index 87c5591f..bcdc5d01 100755 --- a/nodemgmt-scripts.sh +++ b/nodemgmt-scripts.sh @@ -27,7 +27,7 @@ CHECK_DOCKER_SERVICES(){ nid=1 for nip in "${!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 NCMD=''; LH='- localhost' + if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then NCMD=''; LH='- localhost' else NCMD="ssh root@${nip}"; LH='' fi if [ "${NCMD}" != "" ]; then @@ -138,7 +138,7 @@ SET-PERMISSIONS(){ if [ "${1}" = "gitea" ]; then nid=1 for nip in "${WEB_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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then NCMD='' else NCMD="ssh root@${nip}" @@ -163,7 +163,7 @@ SET-PERMISSIONS(){ elif [ "${1}" = "pdnsadmin" ]; then nid=1 for nip in "${WEB_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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then NCMD='' else NCMD="ssh root@${nip}" @@ -185,7 +185,7 @@ SET-PERMISSIONS(){ done elif [ "${1}" = "nextcloud" ]; then nip=${NC_HOSTS[0]} - 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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then NCMD='' else NCMD="ssh root@${nip}" @@ -215,7 +215,7 @@ SET-PERMISSIONS(){ for nip in "${MYSQL_HOSTS[@]}"; do checkhost=$(CHECK_HOST ${nip}) if [ "${checkhost}" != "false" ]; then - 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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -235,7 +235,7 @@ SET-PERMISSIONS(){ for nip in "${WEB_HOSTS[@]}"; do checkhost=$(CHECK_HOST ${nip}) if [ "${checkhost}" != "false" ]; then - 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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -283,16 +283,12 @@ SET-PERMISSIONS(){ } 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 [[ "${MIP}" == *"${nip}"* ]]; then + if [[ "${RUN_NODE_IP}" == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -328,7 +324,7 @@ SERVICE(){ sleep 5s for nip in "${GL_HOSTS[@]}"; do - if [[ "${MIP}" == *"${nip}"* ]]; then + if [[ "${RUN_NODE_IP}" == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -379,33 +375,10 @@ SERVICE(){ else if [ "${4}" != "all" ]; then - for NTYPE in "${NM_NODE_TYPES[@]}"; do - var=${NTYPE}_HOSTS[@] - NODE_TYPE="" - for nip in "${!var}"; do - if [[ "${MIP}" == *"${nip}"* ]]; then - NODE_TYPE=${NTYPE}; - break 2 - fi - done - done - - if [ "${NODE_TYPE}" == "" ] && [ ${#TSI} != 0 ]; then - for NTYPE in "${NM_NODE_TYPES[@]}"; do - var=${NTYPE}_HOSTS[@] - for nip in "${!var}"; do - if [[ "${TSIP}" == *"${nip}"* ]]; then - NODE_TYPE=${NTYPE}; - break 2 - fi - done - done - fi - - if [ "${NODE_TYPE}" != "" ]; then - NT_HOSTS=${NODE_TYPE}_HOSTS[@] - NT_HOST=${NODE_TYPE}_HOSTS[0] - NTS=("${NODE_TYPE}"); + if [ "${RUN_NODE_TYPE}" != "" ]; then + NT_HOSTS=${RUN_NODE_TYPE}_HOSTS[@] + NT_HOST=${RUN_NODE_TYPE}_HOSTS[0] + NTS=("${RUN_NODE_TYPE}"); else NTS=(${NM_NODE_TYPES[*]}) fi @@ -414,7 +387,7 @@ SERVICE(){ NTS=(${NM_NODE_TYPES[*]}) fi - # if [ "${NODE_TYPE}" == "" ]; then + # if [ "${RUN_NODE_TYPE}" == "" ]; then # # fi @@ -440,30 +413,30 @@ SERVICE(){ if [ "${1}" = "nginx" ]; then - [ "${NODE_TYPE}" != "" ] && [ "${NM_REPL_NGINX_PATHS[${NODE_TYPE}]}" != "" ] && + [ "${RUN_NODE_TYPE}" != "" ] && [ "${NM_REPL_NGINX_PATHS[${RUN_NODE_TYPE}]}" != "" ] && if [ "${2}" = "restart" ] || [ "${2}" = "reload" ]; then if [ "${3}" != "ns" ]; then if [ "${3}" != "q" ]; then echo -en "${idsCL[LightYellow]}Verifying replication across the nodes... ${idsCL[Default]}" fi - if [[ "${MIP}" == *"${!NT_HOST}"* ]]; then + if [[ "${RUN_NODE_IP}" == *"${!NT_HOST}"* ]]; then PH_CMD="" else PH_CMD="ssh root@${!NT_HOST}" fi - ${PH_CMD} touch ${NM_REPL_NGINX_PATHS[${NODE_TYPE}]}/test.repl - # ${PH_CMD} "echo -e \"Service ${1} ${2}\" >> ${NM_REPL_NGINX_PATHS[${NODE_TYPE}]}/test.repl" + ${PH_CMD} touch ${NM_REPL_NGINX_PATHS[${RUN_NODE_TYPE}]}/test.repl + # ${PH_CMD} "echo -e \"Service ${1} ${2}\" >> ${NM_REPL_NGINX_PATHS[${RUN_NODE_TYPE}]}/test.repl" for nip in "${!NT_HOSTS}"; do checkhost=$(CHECK_HOST ${nip}) if [ "${checkhost}" != "false" ] && [ "${nip}" != "${!NT_HOST}" ]; then checked=false until [ "${checked}" = "true" ]; do - checked="`${PH_CMD} ssh root@${nip} [ -f ${NM_REPL_NGINX_PATHS[${NODE_TYPE}]}/test.repl ] && [ $(expr $(date +%s) - $(stat -L --format %Y ${NM_REPL_NGINX_PATHS[${NODE_TYPE}]}/test.repl)) -le 90 ] && echo true`" + checked="`${PH_CMD} ssh root@${nip} [ -f ${NM_REPL_NGINX_PATHS[${RUN_NODE_TYPE}]}/test.repl ] && [ $(expr $(date +%s) - $(stat -L --format %Y ${NM_REPL_NGINX_PATHS[${RUN_NODE_TYPE}]}/test.repl)) -le 90 ] && echo true`" done fi done - ${PH_CMD} rm -f ${NM_REPL_NGINX_PATHS[${NODE_TYPE}]}/test.repl + ${PH_CMD} rm -f ${NM_REPL_NGINX_PATHS[${RUN_NODE_TYPE}]}/test.repl fi fi @@ -473,7 +446,7 @@ SERVICE(){ if [ "${3}" != "q" ]; then echo -en "${idsCL[LightYellow]}Verifying Apache config and ssl cert replication across the nodes... ${idsCL[Default]}" fi - if [[ "${MIP}" == *"${!NT_HOST}"* ]]; then + if [[ "${RUN_NODE_IP}" == *"${!NT_HOST}"* ]]; then PH_CMD="ssh root@localhost" else PH_CMD="ssh root@${!NT_HOST}" @@ -520,7 +493,7 @@ SERVICE(){ for nip in "${var2[@]}"; do - # if [[ "${MIP}" == *"${3}"* ]]; then GO=true; + # if [[ "${RUN_NODE_IP}" == *"${3}"* ]]; then GO=true; # elif [ ! -z ${3+x} ] || [ "${3}" == "q" ]; then GO=true; # else GO=false; # fi @@ -530,7 +503,7 @@ SERVICE(){ else nodename="${NM_HOSTNAMES[${nip}]}[${nip}]" fi - if [[ "${MIP}" == *"${nip}"* ]]; then + if [[ "${RUN_NODE_IP}" == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -592,7 +565,7 @@ HAPROXY-CONFIG() { if [[ " ${MYSQL_SERVICES_CHECK[*]} " =~ " haproxy " ]]; then nid=1 for nip in "${MYSQL_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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -613,7 +586,7 @@ HAPROXY-CONFIG() { if [[ " ${WEB_SERVICES_CHECK[*]} " =~ " haproxy " ]]; then nid=1 for nip in "${WEB_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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -633,7 +606,7 @@ HAPROXY-CONFIG() { if [[ " ${LB_SERVICES_CHECK[*]} " =~ " haproxy " ]]; then nid=1 for nip in "${LB_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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -724,7 +697,7 @@ KEEPALIVE-CONFIG() { if [[ " ${MYSQL_SERVICES_CHECK[*]} " =~ " keepalived " ]]; then nid=1 for nip in "${MYSQL_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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -745,7 +718,7 @@ KEEPALIVE-CONFIG() { if [[ " ${WEB_SERVICES_CHECK[*]} " =~ " keepalived " ]]; then nid=1 for nip in "${WEB_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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' NCMD='' else @@ -779,7 +752,7 @@ NODEUPDATE() { echo -e "${idsCL[LightGreen]}Updating All Nodes${idsCL[Default]}" echo -e "${idsCL[LightGreen]}-------------------------------------------${idsCL[Default]}" nmip=${NM_NODEMANAGER} - if [[ $(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1) == *"${nmip}"* ]]; then + if [[ ${RUN_NODE_IP} == *"${nmip}"* ]]; then nmip='localhost' fi @@ -801,7 +774,7 @@ NODEUPDATE() { nid=1 var=${NTYPE}_HOSTS[@] for nip in "${!var}"; 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 [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then nip='localhost ' fi NCMD="ssh -tq root@${nip}" @@ -1017,7 +990,7 @@ RUN_COMMAND(){ var=${NTYPE}_HOSTS[@] for nip in "${!var}"; 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 NCMD=''; LH='- localhost' + if [[ ${RUN_NODE_IP} == *"${nip}"* ]]; then NCMD=''; LH='- localhost' else NCMD="ssh root@${nip}"; LH='' fi echo -e " ${idsST[Bold]}${idsCL[LightCyan]}${NM_HOSTNAMES[${nip}]}[${nip}]${idsST[Reset]}${idsCL[LightCyan]} ${idsCL[LightYello]}${LH}${idsCL[Default]}"