Update nodemgmt-scripts.sh

This commit is contained in:
2022-10-14 22:56:50 -05:00
parent b4282f535d
commit ccf2062846

View File

@@ -1365,192 +1365,277 @@ SERVICES(){
SERVICE(){
NODE_TYPE=''
#var=NC_HOSTS[@]
for NTYPE in "${NODE_TYPES[@]}"; do
var=${NTYPE}_HOSTS[@]
for nip in "${!var}"; do
IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
if [ "$1" = "glusterd" ]; then
for nip in "${GL_HOSTS[@]}"; do
if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${nip}"* ]]; then
NODE_TYPE=${NTYPE};
break 2
nip='localhost '
NCMD=''
else
NCMD="ssh root@${nip}"
fi
done
done
if [ "$NODE_TYPE" = "NC" ]; then
NT_HOSTS=NC_HOSTS[@]
NT_HOST=NC_HOSTS[0]
NTS=('NC'); #NTS=$NTS1[@]
elif [ "$NODE_TYPE" = "LB" ]; then
NT_HOSTS=LB_HOSTS[@]
NT_HOST=LB_HOSTS[0]
NTS=('LB'); #NTS=$NTS1[@]
elif [ "$NODE_TYPE" = "WEB" ]; then
NT_HOSTS=WEB_HOSTS[@]
NT_HOST=WEB_HOSTS[0]
NTS=('WEB'); #NTS=$NTS1[@]
elif [ "$NODE_TYPE" = "MYSQL" ]; then
NT_HOSTS=MYSQL_HOSTS[@]
NT_HOST=MYSQL_HOSTS[0]
NTS=('MYSQL'); #NTS=$NTS1[@]
elif [ "${1}" = "nginx" ]; then
NT_HOSTS=WEB_HOSTS[@]
NT_HOST=WEB_HOSTS[0]
NTS=('WEB'); #NTS=NTS1[@]
# NTS=$NODE_TYPES
else
NTS=(${NODE_TYPES[*]})
fi
if [ "${3}" != "q" ]; then
if [ "${NM_SERVICES[${1}]}" = "" ]; then
echo -e "${idsCL[Red]}(${1}) is not an allowed service.${idsCL[Default]}"
exit 1
fi
if [ "${NM_SRVCOPTS[${2}]}" = "" ]; then
echo -e "${idsCL[Red]}(${2}) is not an allowed service action.${idsCL[Default]}"
exit 1
fi
if [ "$2" = "start" ] && [ "$1" = "haproxy" ]; then
TACT='restart'
else
TACT="${2}"
fi
echo
echo -e "${idsCL[LightGreen]}[[ ${NM_SERVICES[${1}]} ${NM_SRVCOPTS[${2}]}ing ]]${idsCL[Default]}"
echo -e "${idsCL[LightGreen]}-------------------------------------------${idsCL[Default]}"
fi
if [ "${1}" = "nginx-x" ]; then
if [ "${2}" = "restart" ] || [ "${2}" = "reload" ]; then
if [ "${3}" != "ns" ]; then
if [ "${3}" != "q" ]; then
echo -en "${NM_SRVCOPTS[${2}]}ing on '$nip'... ${idsCL[Default]}"
fi
checkhost=$(CHECK_HOST ${nip})
if [ "${checkhost}" != "false" ]; then
#$NCMD systemctl $2 $1
if [ "${3}" != "q" ]; then
echo -en "${idsCL[LightYellow]}Verifying nginx config and ssl cert replication across the nodes... ${idsCL[Default]}"
if [[ "enable,disable" = *"${2}"* ]] || [ "${1}" = "daemon-reload" ]; then
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
elif [ "$(${NCMD} systemctl is-active ${1})" = "active" ]; then
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
elif [ "$2" = "stop" ]; then
echo -e "${idsCL[Red]}STOPPED${idsCL[Default]}"
else
echo -e "${idsCL[Red]}ERROR${idsCL[Default]}"
fi
fi
if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${!NT_HOST}"* ]]; then
PH_CMD="ssh root@localhost"
elif [ "${3}" != "q" ]; then
echo -e "${idsCL[Red]}Node is Down${idsCL[Default]}"
fi
done
if [ "${2}" = "start" ] || [ "${2}" = "restart" ]; then
echo
sleep 5s
for nip in "${GL_HOSTS[@]}"; do
if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${nip}"* ]]; then
nip='localhost '
NCMD=''
else
PH_CMD="ssh root@${!NT_HOST}"
NCMD="ssh root@${nip}"
fi
${PH_CMD} "echo -e \"Service ${1} ${2}\" > /etc/nginx/test.repl"
# if [ "$NODE_TYPE" != "NC" ]; then
# ${PH_CMD} "echo -e \"Service ${1} ${2}\" > /etc/letsencrypt/test.repl"
# fi
for nip in "${!NT_HOSTS}"; do
checkhost=$(CHECK_HOST ${nip})
if [ "${checkhost}" != "false" ]; then
if [ "${nip}" != "${!NT_HOST}" ]; then
checked=false
until [ "${checked}" = "" ]; do
checked="`${PH_CMD} \"ssh root@${nip} 'if [ -f /etc/nginx/test.repl ]; then cat /etc/nginx/test.repl; fi' | diff - /etc/nginx/test.repl\"`"
# checked="`${PH_CMD} \"ssh root@${nip} 'if [ -f /etc/nginx/test.repl ]; then cat /etc/letsencrypt/test.repl; fi' | diff - /etc/letsencrypt/test.repl\"`"
if [ "${3}" != "q" ]; then
echo -en "Mounting drive on ${NM_NODETYPES[$NTYPE]}-Node${nid} ($nip)... ${idsCL[Default]}"
fi
checkhost=$(CHECK_HOST ${nip})
if [ "${checkhost}" != "false" ]; then
#$NCMD mount -a
if [ "${3}" != "q" ]; then
IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
for NTYPE in "${NODE_TYPES[@]}"; do
var=${NTYPE}_HOSTS[@]
for nip in "${!var}"; do
if [[ IP == *"${nip}"* ]]; then
NODE_TYPE=${NTYPE};
break 2
fi
done
done
if [ "$NODE_TYPE" = "NC" ]; then
var=`ls -l /mnt/Nextcloud-Data | wc -l`
elif [ "$NODE_TYPE" = "WEB" ]; then
var=`ls -l /mnt/web-data | wc -l`
fi
if [ $var -gt 1 ]; then
echo -e "${idsCL[Green]}MOUNTED${idsCL[Default]}"
else
echo -e "${idsCL[Red]}NOT MOUNTED${idsCL[Default]}"
fi
fi
done
${PH_CMD} rm -f /etc/nginx/test.repl
# if [ "$NODE_TYPE" != "NC" ]; then
# ${PH_CMD} rm -f /etc/letsencrypt/test.repl
# fi
fi
elif [ "${3}" != "q" ]; then
echo -e "${idsCL[Red]}Node is Down${idsCL[Default]}"
fi
done
fi
elif [ "${1}" = "apache2-x" ]; then
if [ "${2}" = "restart" ] || [ "${2}" = "reload" ]; then
if [ "${3}" != "ns" ]; then
if [ "${3}" != "q" ]; then
echo -en "${idsCL[LightYellow]}Verifying Apache config and ssl cert replication across the nodes... ${idsCL[Default]}"
else
IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
for NTYPE in "${NODE_TYPES[@]}"; do
var=${NTYPE}_HOSTS[@]
for nip in "${!var}"; do
if [[ IP == *"${nip}"* ]]; then
NODE_TYPE=${NTYPE};
break 2
fi
if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${!NT_HOST}"* ]]; then
PH_CMD="ssh root@localhost"
else
PH_CMD="ssh root@${!NT_HOST}"
fi
echo "HERE: '$PH_CMD'"
${PH_CMD} "echo -e \"Service ${1} ${2}\" > /etc/apache2/test.repl"
for nip in "${!NT_HOSTS}"; do
checkhost=$(CHECK_HOST ${nip})
if [ "${checkhost}" != "false" ]; then
if [ "${nip}" != "${!NT_HOST}" ]; then
checked=false
until [ "${checked}" = "" ]; do
checked="`${PH_CMD} \"ssh root@${nip} 'if [ -f /etc/apache2/test.repl ]; then cat /etc/apache2/test.repl; fi' | diff - /etc/apache2/test.repl\"`"
done
fi
fi
done
${PH_CMD} rm -f /etc/apache2/test.repl
fi
done
done
if [ "$NODE_TYPE" = "NC" ]; then
NT_HOSTS=NC_HOSTS[@]
NT_HOST=NC_HOSTS[0]
NTS=('NC'); #NTS=$NTS1[@]
elif [ "$NODE_TYPE" = "LB" ]; then
NT_HOSTS=LB_HOSTS[@]
NT_HOST=LB_HOSTS[0]
NTS=('LB'); #NTS=$NTS1[@]
elif [ "$NODE_TYPE" = "WEB" ]; then
NT_HOSTS=WEB_HOSTS[@]
NT_HOST=WEB_HOSTS[0]
NTS=('WEB'); #NTS=$NTS1[@]
elif [ "$NODE_TYPE" = "MYSQL" ]; then
NT_HOSTS=MYSQL_HOSTS[@]
NT_HOST=MYSQL_HOSTS[0]
NTS=('MYSQL'); #NTS=$NTS1[@]
elif [ "${1}" = "nginx" ]; then
NT_HOSTS=WEB_HOSTS[@]
NT_HOST=WEB_HOSTS[0]
NTS=('WEB'); #NTS=NTS1[@]
# NTS=$NODE_TYPES
else
NTS=(${NODE_TYPES[*]})
fi
fi
if [ "${3}" != "q" ]; then
echo -e "${idsCL[Green]}Completed${idsCL[Default]}"
echo
fi
for NTYPE in "${NTS[@]}"; do
var1=${NTYPE}SERVICES_CHECK
if [[ "${!var1}" = *"${1}"* ]]; then
nid=1
if [ "${3}" != "" ]; then
var2=(${3})
else
var2=${NTYPE}_HOSTS[@]
IFS=' '
var2=(${!var2})
unset IFS
if [ "${3}" != "q" ]; then
if [ "${NM_SERVICES[${1}]}" = "" ]; then
echo -e "${idsCL[Red]}(${1}) is not an allowed service.${idsCL[Default]}"
exit 1
fi
for nip in "${var2[@]}"; do
# if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${3}"* ]]; then GO=true;
# elif [ ! -z ${3+x} ] || [ "${3}" == "q" ]; then GO=true;
# else GO=false;
# fi
# if [ "${GO}" == "true" ]; then
if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${nip}"* ]]; then
nip='localhost '
NCMD=''
if [ "${NM_SRVCOPTS[${2}]}" = "" ]; then
echo -e "${idsCL[Red]}(${2}) is not an allowed service action.${idsCL[Default]}"
exit 1
fi
if [ "$2" = "start" ] && [ "$1" = "haproxy" ]; then
TACT='restart'
else
TACT="${2}"
fi
echo
echo -e "${idsCL[LightGreen]}[[ ${NM_SERVICES[${1}]} ${NM_SRVCOPTS[${2}]}ing ]]${idsCL[Default]}"
echo -e "${idsCL[LightGreen]}-------------------------------------------${idsCL[Default]}"
fi
if [ "${1}" = "nginx-x" ]; then
if [ "${2}" = "restart" ] || [ "${2}" = "reload" ]; then
if [ "${3}" != "ns" ]; then
if [ "${3}" != "q" ]; then
echo -en "${idsCL[LightYellow]}Verifying nginx config and ssl cert replication across the nodes... ${idsCL[Default]}"
fi
if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${!NT_HOST}"* ]]; then
PH_CMD="ssh root@localhost"
else
NCMD="ssh root@${nip}"
PH_CMD="ssh root@${!NT_HOST}"
fi
NOGOCHK=true;
if [ "${1}" == "gitea" ] || [ "${1}" == "pdnsadmin" ] || [ "${1}" == "pdnsadmin.socket" ]; then
if [[ $($NCMD /sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) != *10.10.1.120* ]]; then
NOGOCHK=false;
fi
fi
if [ "${NOGOCHK}" == "true" ]; then
if [ "${3}" != "q" ]; then
echo -en "${NM_SRVCOPTS[${2}]}ing on ${NM_NODETYPES[$NTYPE]}-Node${nid} ($nip)... ${idsCL[Default]}"
fi
${PH_CMD} "echo -e \"Service ${1} ${2}\" > /etc/nginx/test.repl"
# if [ "$NODE_TYPE" != "NC" ]; then
# ${PH_CMD} "echo -e \"Service ${1} ${2}\" > /etc/letsencrypt/test.repl"
# fi
for nip in "${!NT_HOSTS}"; do
checkhost=$(CHECK_HOST ${nip})
if [ "${checkhost}" != "false" ]; then
$NCMD systemctl $2 $1
if [ "${3}" != "q" ]; then
if [[ "enable,disable" = *"${2}"* ]] || [ "${1}" = "daemon-reload" ]; then
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
elif [ "$(${NCMD} systemctl is-active ${1})" = "active" ]; then
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
elif [ "$2" = "stop" ]; then
echo -e "${idsCL[Red]}STOPPED${idsCL[Default]}"
else
echo -e "${idsCL[Red]}ERROR${idsCL[Default]}"
fi
if [ "${nip}" != "${!NT_HOST}" ]; then
checked=false
until [ "${checked}" = "" ]; do
checked="`${PH_CMD} \"ssh root@${nip} 'if [ -f /etc/nginx/test.repl ]; then cat /etc/nginx/test.repl; fi' | diff - /etc/nginx/test.repl\"`"
# checked="`${PH_CMD} \"ssh root@${nip} 'if [ -f /etc/nginx/test.repl ]; then cat /etc/letsencrypt/test.repl; fi' | diff - /etc/letsencrypt/test.repl\"`"
done
fi
elif [ "${3}" != "q" ]; then
echo -e "${idsCL[Red]}Node is Down${idsCL[Default]}"
fi
done
${PH_CMD} rm -f /etc/nginx/test.repl
# if [ "$NODE_TYPE" != "NC" ]; then
# ${PH_CMD} rm -f /etc/letsencrypt/test.repl
# fi
fi
fi
elif [ "${1}" = "apache2-x" ]; then
if [ "${2}" = "restart" ] || [ "${2}" = "reload" ]; then
if [ "${3}" != "ns" ]; then
if [ "${3}" != "q" ]; then
echo -en "${idsCL[LightYellow]}Verifying Apache config and ssl cert replication across the nodes... ${idsCL[Default]}"
fi
# fi
nid=`expr $nid + 1`
# if [ "${1}" = "gitea" ]; then
# break
# fi
done
if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${!NT_HOST}"* ]]; then
PH_CMD="ssh root@localhost"
else
PH_CMD="ssh root@${!NT_HOST}"
fi
echo "HERE: '$PH_CMD'"
${PH_CMD} "echo -e \"Service ${1} ${2}\" > /etc/apache2/test.repl"
for nip in "${!NT_HOSTS}"; do
checkhost=$(CHECK_HOST ${nip})
if [ "${checkhost}" != "false" ]; then
if [ "${nip}" != "${!NT_HOST}" ]; then
checked=false
until [ "${checked}" = "" ]; do
checked="`${PH_CMD} \"ssh root@${nip} 'if [ -f /etc/apache2/test.repl ]; then cat /etc/apache2/test.repl; fi' | diff - /etc/apache2/test.repl\"`"
done
fi
fi
done
${PH_CMD} rm -f /etc/apache2/test.repl
fi
fi
fi
done
if [ "${3}" != "q" ]; then
echo -e "${idsCL[Green]}Completed${idsCL[Default]}"
echo
fi
for NTYPE in "${NTS[@]}"; do
var1=${NTYPE}SERVICES_CHECK
if [[ "${!var1}" = *"${1}"* ]]; then
nid=1
if [ "${3}" != "" ]; then
var2=(${3})
else
var2=${NTYPE}_HOSTS[@]
IFS=' '
var2=(${!var2})
unset IFS
fi
for nip in "${var2[@]}"; do
# if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${3}"* ]]; then GO=true;
# elif [ ! -z ${3+x} ] || [ "${3}" == "q" ]; then GO=true;
# else GO=false;
# fi
# if [ "${GO}" == "true" ]; then
if [[ $(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) == *"${nip}"* ]]; then
nip='localhost '
NCMD=''
else
NCMD="ssh root@${nip}"
fi
NOGOCHK=true;
if [ "${1}" == "gitea" ] || [ "${1}" == "pdnsadmin" ] || [ "${1}" == "pdnsadmin.socket" ]; then
if [[ $($NCMD /sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) != *10.10.1.120* ]]; then
NOGOCHK=false;
fi
fi
if [ "${NOGOCHK}" == "true" ]; then
if [ "${3}" != "q" ]; then
echo -en "${NM_SRVCOPTS[${2}]}ing on ${NM_NODETYPES[$NTYPE]}-Node${nid} ($nip)... ${idsCL[Default]}"
fi
checkhost=$(CHECK_HOST ${nip})
if [ "${checkhost}" != "false" ]; then
$NCMD systemctl $2 $1
if [ "${3}" != "q" ]; then
if [[ "enable,disable" = *"${2}"* ]] || [ "${1}" = "daemon-reload" ]; then
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
elif [ "$(${NCMD} systemctl is-active ${1})" = "active" ]; then
echo -e "${idsCL[Green]}OK${idsCL[Default]}"
elif [ "$2" = "stop" ]; then
echo -e "${idsCL[Red]}STOPPED${idsCL[Default]}"
else
echo -e "${idsCL[Red]}ERROR${idsCL[Default]}"
fi
fi
elif [ "${3}" != "q" ]; then
echo -e "${idsCL[Red]}Node is Down${idsCL[Default]}"
fi
fi
# fi
nid=`expr $nid + 1`
# if [ "${1}" = "gitea" ]; then
# break
# fi
done
fi
done
fi
if [ "${3}" != "q" ]; then
echo
@@ -2015,6 +2100,8 @@ if [ ${action-x} ]; then
SERVICE php8.0-fpm ${3} ${4}
SERVICE php8.1-fpm ${3} ${4}
SERVICE nginx ${3} ${4}
elif [ "$2" = "glusterdxx" ]; then
SERVICE glusterd stop
else
SERVICE ${2} ${3} ${4}
fi;;