diff --git a/mm-scripts.sh b/mm-scripts.sh index 91727e5..592c4b2 100755 --- a/mm-scripts.sh +++ b/mm-scripts.sh @@ -325,11 +325,35 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf for srvc in "${SERVICES_CHECK[@]}"; do if [ "$(systemctl is-active ${srvc})" != "active" ]; then /bin/systemctl start ${srvc} - sleep 5s fi checkport=$(lsof -Pi :${MM_SERVICE_PORTS[${srvc}]} -sTCP:LISTEN -t) - if [ "${checkport}" == "" ] && [ "${MM_UPDATE_REPO[${srvc}]}" != "" ]; then - UPDATESERVICE {$srvc} >/dev/null 2>&1 + + checked=false + cc=0 + until [ "${checked}" = "" ]; do + if [ "${checkport}" != "" ]; then + checked="" + fi + if [ "${checked}" == "false" ] && [ ${cc} -eq 15 ]; then + echo -e "${idsCL[Red]}${srvc} Service is not starting properly, will try and update${idsCL[Default]}" + echo "$(date) - ${srvc} Service is not starting properly, will try and update" >> $logfile + SENDNOTICE "${srvc} Service Issue" "${srvc} Service is not starting properly, will try and update" 1 + checked="" + tryupdate=true + + msg="Updating Service" + c=0; spc=''; spc1=$((${cw_spc}-${#msg})) + until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done + echo -en "${idsCL[LightCyan]}${msg}${spc} ${idsCL[White]}: ${idsCL[Default]}" + fi + ((cc=${cc}+1)) + sleep 1s + checkport=$(lsof -Pi :${MM_SERVICE_PORTS[${srvc}]} -sTCP:LISTEN -t) + + done + + if ([ "${checkport}" == "" ] || [ ${tryupdate} == true ]) && [ "${MM_UPDATE_REPO[${srvc}]}" != "" ]; then + UPDATESERVICE ${srvc} >/dev/null 2>&1 fi done