Update nodemgmt-scripts.sh

This commit is contained in:
2023-04-27 09:15:06 -05:00
parent a7093e6155
commit 0e232a76ed

View File

@@ -29,7 +29,7 @@ STATUS(){
######################## ########################
if [ "${ST_ACTION}" == "report" ] || [ "${ST_ACTION}" == "repl" ] || [ "${ST_ACTION}" == "check" ] || [ "${ST_ACTION}" == "" ]; then if [ "${ST_ACTION}" == "report" ] || [ "${ST_ACTION}" == "repl" ] || [ "${ST_ACTION}" == "check" ] || [ "${ST_ACTION}" == "" ]; then
if [ "${ST_ACTION}" != "check" ]; then if [ "${ST_ACTION}" != "check" ]; then
echo -en "${idsCL[LightCyan]}Setting up replication checks for next status check ... ${idsCL[Default]}" echo -en "${idsCL[LightCyan]}Setting up replication checks ... ${idsCL[Default]}"
fi fi
for NTYPE in "${NODE_TYPES[@]}"; do for NTYPE in "${NODE_TYPES[@]}"; do
PH=${NTYPE}_HOSTS[0] PH=${NTYPE}_HOSTS[0]
@@ -175,89 +175,91 @@ STATUS(){
if [ "${ST_ACTION}" != "dockers" ]; then if [ "${ST_ACTION}" != "dockers" ]; then
var2=${NTYPE}_SERVICES_CHECK[@] var2=${NTYPE}_SERVICES_CHECK[@]
for srvc in "${!var2}"; do srvcstotest="$(join_by , ${!var2})"
NOGOCHK=true; echo "$nip - $srvcstotest"
# if [ ${srvc} = "gitea" ] || [ ${srvc} = "pdnsadmin" ] || [ ${srvc} = "pdnsadmin.socket" ]; then
if [ ${srvc} = "gitea" ]; then
if [[ $($NCMD /sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) != *10.10.1.120* ]] && [[ "${NTYPE}" != "LPD" ]]; then
NOGOCHK=false;
fi
fi
if [ ${NOGOCHK} = true ]; then
if [ "${ST_ACTION}" != "check" ]; then # for srvc in "${!var2}"; do
if [ "${ST_ACTION}" != "report" ]; then # NOGOCHK=true;
c=0; cw=30; spc='' # [ "${srvc}" == "gitea" ] && [ "${NTYPE}" == "WEB" ] && [[ $($NCMD /sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) != *${WEB_HOSTS[0]}* ]] && NOGOCHK=false;
spc1=${cw}-${#NM_SERVICES[${srvc}]} # if [ ${NOGOCHK} = true ]; then
until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done # if [ "${ST_ACTION}" != "check" ]; then
else # if [ "${ST_ACTION}" != "report" ]; then
spc=' ' # c=0; cw=30; spc=''
fi # spc1=${cw}-${#NM_SERVICES[${srvc}]}
echo -en " ${NM_SERVICES[${srvc}]}$spc: " # until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
fi # else
srvctst=$(${NCMD} systemctl is-active ${srvc}) # spc=' '
#echo "${NCMD} systemctl is-active ${srvc} = ${srvctst}" # fi
#if [ "${srvctst}" = "active" ]; then echo "yes"; else echo "no"; fi # echo -en " ${NM_SERVICES[${srvc}]}$spc: "
if [ "${srvctst}" != "active" ] && [ "${srvc}" = "mysql" ]; then # fi
mysqlgo=false; # srvctst=$(${NCMD} systemctl is-active ${srvc})
[ "$(${NCMD} systemctl is-active mariadb)" = "active" ] && mysqlgo=true; # if [ "${srvctst}" != "active" ] && [ "${srvc}" = "mysql" ]; then
elif [ "${srvctst}" != "active" ] && [ "${srvc}" = "mariadb" ]; then # mysqlgo=false;
mysqlgo=false; # [ "$(${NCMD} systemctl is-active mariadb)" = "active" ] && mysqlgo=true;
[ "$(${NCMD} systemctl is-active mysql)" = "active" ] && mysqlgo=true; # elif [ "${srvctst}" != "active" ] && [ "${srvc}" = "mariadb" ]; then
elif [ "${srvctst}" = "active" ] && ([ "${srvc}" = "mysql" ] || [ "${srvc}" = "mariadb" ]); then # mysqlgo=false;
mysqlgo=true # [ "$(${NCMD} systemctl is-active mysql)" = "active" ] && mysqlgo=true;
fi # elif [ "${srvctst}" = "active" ] && ([ "${srvc}" = "mysql" ] || [ "${srvc}" = "mariadb" ]); then
# echo "mysqlgo=${mysqlgo}" # mysqlgo=true
if [ "${srvctst}" != "active" ] && [ "${mysqlgo}" != "true" ]; then # fi
if [ ! -f ${FOLDER}/${nip}-${srvc}.down ]; then # # echo "mysqlgo=${mysqlgo}"
if [ "${ST_ACTION}" != "check" ]; then # if [ "${srvctst}" != "active" ] && [ "${mysqlgo}" != "true" ]; then
echo -e "${idsCL[Red]}Not Running${idsCL[Default]}" # if [ ! -f ${FOLDER}/${nip}-${srvc}.down ]; then
fi # if [ "${ST_ACTION}" != "check" ]; then
SENDNOTICE "${NM_NODETYPES[$NTYPE]}-Node${nid}-${nip}" "${NM_SERVICES[${srvc}]} is down" 1 # echo -e "${idsCL[Red]}Not Running${idsCL[Default]}"
touch ${FOLDER}/${nip}-${srvc}.down # fi
echo "$(date) - ${nip} - ${NM_NODETYPES[$NTYPE]}-Node${nid} - ${NM_SERVICES[${srvc}]} is down" >> ${LOGFILE} # SENDNOTICE "${NM_NODETYPES[$NTYPE]}-Node${nid}-${nip}" "${NM_SERVICES[${srvc}]} is down" 1
# touch ${FOLDER}/${nip}-${srvc}.down
else # echo "$(date) - ${nip} - ${NM_NODETYPES[$NTYPE]}-Node${nid} - ${NM_SERVICES[${srvc}]} is down" >> ${LOGFILE}
errtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}-${srvc}.down) #
if [ $errtime -gt ${RENOTIFY} ]; then # else
if [ ! -f ${FOLDER}/${nip}-${srvc}.errtime ]; then # errtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}-${srvc}.down)
mv ${FOLDER}/${nip}-${srvc}.down ${FOLDER}/${nip}-${srvc}.errtime # if [ $errtime -gt ${RENOTIFY} ]; then
fi # if [ ! -f ${FOLDER}/${nip}-${srvc}.errtime ]; then
toterrtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}-${srvc}.errtime) # mv ${FOLDER}/${nip}-${srvc}.down ${FOLDER}/${nip}-${srvc}.errtime
touch ${FOLDER}/${nip}-${srvc}.down # fi
if [ "${srvc}" = "mysql" ]; then # toterrtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}-${srvc}.errtime)
${NCMD} systemctl restart ${srvc} # touch ${FOLDER}/${nip}-${srvc}.down
fi # if [ "${srvc}" = "mysql" ]; then
fi # ${NCMD} systemctl restart ${srvc}
if [ "${ST_ACTION}" != "check" ]; then # fi
echo -e "${idsCL[Red]}Not running for $(SHOW_TIME ${toterrtime})${idsCL[Default]}" # fi
fi # if [ "${ST_ACTION}" != "check" ]; then
fi # echo -e "${idsCL[Red]}Not running for $(SHOW_TIME ${toterrtime})${idsCL[Default]}"
else # fi
if [ "${ST_ACTION}" != "check" ]; then # fi
echo -e "${idsCL[Green]}Running${idsCL[Default]}" # else
fi # if [ "${ST_ACTION}" != "check" ]; then
if [ -f ${FOLDER}/${nip}-${srvc}.down ]; then # echo -e "${idsCL[Green]}Running${idsCL[Default]}"
if [ -f ${FOLDER}/${nip}-${srvc}.errtime ]; then # fi
toterrtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}-${srvc}.errtime) # if [ -f ${FOLDER}/${nip}-${srvc}.down ]; then
else # if [ -f ${FOLDER}/${nip}-${srvc}.errtime ]; then
toterrtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}-${srvc}.down) # toterrtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}-${srvc}.errtime)
fi # else
SENDNOTICE "${NM_NODETYPES[$NTYPE]}-Node${nid}-${nip}" "${NM_SERVICES[${srvc}]} is back UP! It was down for $(SHOW_TIME ${toterrtime})" # toterrtime=`date +%s`-$(stat -c %Y ${FOLDER}/${nip}-${srvc}.down)
echo "$(date) - ${nip} - ${NM_NODETYPES[$NTYPE]}-Node${nid} - ${NM_SERVICES[${srvc}]} is back up, it was down for $(SHOW_TIME ${toterrtime})" >> ${LOGFILE} # fi
# SENDNOTICE "${NM_NODETYPES[$NTYPE]}-Node${nid}-${nip}" "${NM_SERVICES[${srvc}]} is back UP! It was down for $(SHOW_TIME ${toterrtime})"
rm -f ${FOLDER}/${nip}-${srvc}.down # echo "$(date) - ${nip} - ${NM_NODETYPES[$NTYPE]}-Node${nid} - ${NM_SERVICES[${srvc}]} is back up, it was down for $(SHOW_TIME ${toterrtime})" >> ${LOGFILE}
rm -f ${FOLDER}/${nip}-${srvc}.errtime #
# rm -f ${FOLDER}/${nip}-${srvc}.down
fi # rm -f ${FOLDER}/${nip}-${srvc}.errtime
# if [ "${srvc}" == "pdnsadmin.socket" ] || [ "${srvc}" == "pdnsadmin" ] || [ "${srvc}" == "gitea" ]; then #
if [ "${srvc}" == "gitea" ]; then # fi
rm -f ${FOLDER}/*-${srvc}.down # # if [ "${srvc}" == "pdnsadmin.socket" ] || [ "${srvc}" == "pdnsadmin" ] || [ "${srvc}" == "gitea" ]; then
rm -f ${FOLDER}/*-${srvc}.errtime # if [ "${srvc}" == "gitea" ]; then
fi # rm -f ${FOLDER}/*-${srvc}.down
fi # rm -f ${FOLDER}/*-${srvc}.errtime
[ "${mysqlgo}" = "true" ] && unset mysqlgo # fi
fi # fi
done # [ "${mysqlgo}" = "true" ] && unset mysqlgo
# fi
# done
fi fi
if [[ -v ${NTYPE}_DOCKER ]] && [ "${ST_ACTION}" != "services" ]; then if [[ -v ${NTYPE}_DOCKER ]] && [ "${ST_ACTION}" != "services" ]; then