This commit is contained in:
2023-11-15 22:18:05 -06:00
parent 7ec8040b1f
commit 8c5b2227a3
6 changed files with 36 additions and 51 deletions

View File

@@ -6,11 +6,9 @@ SINGLE_SERVER_SERVICE_CHECK(){
hosts=${1^^}_HOSTS[@]
if [ "${!servicestocheck}" != "" ] || [ "${!dockerstocheck}" != "" ]; then
local_ips=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | awk '/inet/ {print $2}' | cut -d'/' -f1);
local_ip=$(/sbin/ip -o -4 addr list eth0 |grep 255 | awk '{print $4}' | cut -d/ -f1)
if [[ ${local_ips} == *${NM_SINGLESRVR_IP[${1^^}]}* ]]; then
if [[ $(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | awk '/inet/ {print $2}' | cut -d'/' -f1) == *${NM_SINGLESRVR_IP[${1^^}]}* ]]; then
if [ ! -f ${NM_TMPFOLDER}/.singleserver ]; then
SENDNOTICE "Node-Balancing Notice" "Starting SingleServer Services on ${NM_NODETYPES[${1^^}]}-Node${local_ip: -1} (${local_ip}), stopping on other Nodes"
SENDNOTICE "Node-Balancing Notice" "Starting SingleServer Services on ${NM_HOSTNAMES[${RUN_NODE_IP}]} (${RUN_NODE_IP}), stopping on other Nodes"
touch ${NM_TMPFOLDER}/.singleserver
fi
gofor=false
@@ -24,11 +22,11 @@ SINGLE_SERVER_SERVICE_CHECK(){
if [ "${gofor}" == "true" ]; then
for stc in "${!servicestocheck}"; do
if [ "$(systemctl is-active ${stc}.service)" != "active" ]; then
echo "$(date) - ${NM_NODETYPES[${1^^}]}-Node${local_ip: -1} - Starting ${stc} on ${local_ip}, stopping on the other Nodes ..." >> ${NM_LOGFILE}
echo "$(date) - ${NM_HOSTNAMES[${RUN_NODE_IP}]} - Starting ${stc} on ${RUN_NODE_IP}, stopping on the other Nodes ..." >> ${NM_LOGFILE}
[ "${stc}" = "pdnsadmin" ] && stc="pdnsadmin.service pdnsadmin.socket"
for nip in "${!hosts}"; do
if [[ "${local_ip}" != *"${nip}"* ]] && [ "$(CHECK_HOST ${nip})" != "false" ]; then
if [[ "${RUN_NODE_IP}" != *"${nip}"* ]] && [ "$(CHECK_HOST ${nip})" != "false" ]; then
ssh -tq root@${nip} /bin/systemctl stop ${stc}
ssh -tq root@${nip} rm -f ${NM_TMPFOLDER}/.singleserver
fi
@@ -37,12 +35,12 @@ SINGLE_SERVER_SERVICE_CHECK(){
[ "${stc}" = "pdnsadmin" ] && stc="pdnsadmin.socket pdnsadmin.service"
[ "${stc}" = "headscale" ] && sleep 90s
/bin/systemctl start ${stc} &
echo "$(date) - ${NM_NODETYPES[${1^^}]}-Node${local_ip: -1} - ... Done" >> ${NM_LOGFILE}
echo "$(date) - ${NM_HOSTNAMES[${RUN_NODE_IP}]} - ... Done" >> ${NM_LOGFILE}
fi
done
for docker in "${!dockerstocheck}"; do
for nip in "${!hosts}"; do
if [[ "${local_ip}" = *"${nip}"* ]]; then
if [[ "${RUN_NODE_IP}" = *"${nip}"* ]]; then
if [ "docker ps -a | grep ${docker})" ]; then
[ "${docker}" == "authelia" ] && [ ! "$(/usr/bin/docker ps -q -f name=auth_redis)" ] && /usr/bin/docker start auth_redis && sleep 2s >/dev/null 2>&1
[ ! "$(/usr/bin/docker ps -q -f name=${docker})" ] && /usr/bin/docker start ${docker} & >/dev/null 2>&1
@@ -81,7 +79,7 @@ SINGLE_SERVER_SERVICE_CHECK(){
fi
if [ "$(systemctl is-active nginx)" != "active" ]; then
${NM_SCRIPT} service web restart ${local_ip}
${NM_SCRIPT} service web restart ${RUN_NODE_IP}
fi
fi
}