This commit is contained in:
2023-03-04 21:54:54 -06:00
parent a0ddc3266b
commit 7091142ef8
2 changed files with 14 additions and 10 deletions

View File

@@ -52,3 +52,7 @@ MMUPDATECHECK(){
/bin/rm -f ${MMFOLDER}/update.available
fi
}
SENDNOTICE(){
[ "${EMAIL_NOTICE}" != "" ] && echo "${2}" | mail -s "${1}" ${EMAIL_NOTICE}
}

View File

@@ -40,7 +40,7 @@ MMSTART(){
elif [ "${1}" = "check" ] && [ "$(ip link | grep "wg-torguard")" = "" ] && [ ! -f ${MMFOLDER}/mm.vpn* ]; then
GOFORSTART=true;
[ "${EMAIL_NOTICE}" != "" ] && echo "$(date)" | mail -s "Starting Media Management Systems" ${EMAIL_NOTICE}
SENDNOTICE "Starting Media Management Systems" "$(date)"
echo "$(date) - Starting Media Management system - (fresh start)" >> $logfile
echo -e "${idsCL[LightCyan]}Fresh startup${idsCL[Default]}"
@@ -109,7 +109,7 @@ PersistentKeepalive = 25" >> /etc/wireguard/wg-torguard.conf
if [ -f ${MMFOLDER}/mm.vpn.fail ]; then
echo -e "${idsCL[Red]} failed, restarting system${idsCL[Default]}"
echo "$(date) - VPN Failure #2 - restarting system" >> $logfile
[ "${EMAIL_NOTICE}" != "" ] && echo "2nd Failure, will try and restart the VPN" | mail -s "VPN Failure" ${EMAIL_NOTICE}
SENDNOTICE "VPN Failure" "2nd Failure, will try and restart the VPN"
touch ${MMFOLDER}/mm.vpn.fail2
rm -f ${MMFOLDER}/mm.vpn.fail
MMSTOP
@@ -122,14 +122,14 @@ PersistentKeepalive = 25" >> /etc/wireguard/wg-torguard.conf
exit 1
elif [ -f ${MMFOLDER}/mm.vpn.fail2 ]; then
echo "$(date) - VPN Failure #3 - Shutting down Media Management systems" >> $logfile
[ "${EMAIL_NOTICE}" != "" ] && echo "Final Failure, shutting down system" | mail -s "VPN Failure" ${EMAIL_NOTICE}
[ "${EMAIL_NOTICE}" != "" ] && echo SENDNOTICE "VPN Failure" "Final Failure, shutting down system"
MMSTOP
[ $VERBOSE = true ] && DEBUGLOGSTOP
exit 1
else
echo -e "${idsCL[Red]} failed, restarting system${idsCL[Default]}"
echo "$(date) - VPN Failure #1 - restarting system" >> $logfile
[ "${EMAIL_NOTICE}" != "" ] && echo "1st Failure, will try and restart the VPN" | mail -s "VPN Failure" ${EMAIL_NOTICE}
[ "${EMAIL_NOTICE}" != "" ] && echo SENDNOTICE "VPN Failure" "1st Failure, will try and restart the VPN"
touch ${MMFOLDER}/mm.vpn.fail
MMSTOP
sleep 30s
@@ -175,7 +175,7 @@ PersistentKeepalive = 25" >> /etc/wireguard/wg-torguard.conf
if [ "${checked}" == "false" ] && [ ${cc} -eq 10 ]; then
echo -e "${idsCL[Red]}Could not confirm default routes, restarting system!${idsCL[Default]}"
echo "$(date) - Could not confirm default routes, restarting system" >> $logfile
[ "${EMAIL_NOTICE}" != "" ] && echo "Default route failure, will try and restart the VPN" | mail -s "Network Failure" ${EMAIL_NOTICE}
SENDNOTICE "Network Failure" "Default route failure, will try and restart the VPN"
touch ${MMFOLDER}/mm.vpn.fail
MMSTOP
sleep 2m
@@ -205,7 +205,7 @@ PersistentKeepalive = 25" >> /etc/wireguard/wg-torguard.conf
echo -e "${idsCL[Red]}Cannot get an WAN address, restarting system!${idsCL[Default]}"
echo "$(date) - Cannot get an WAN address, restarting system! scip(${scip}) mmip(${mmip})" >> $logfile
[ $VERBOSE = true ] && echo "$(date) - Default Routes: zerogw(${zerogw}) defaultgw(${defaultgw})" >> $logfile
[ "${EMAIL_NOTICE}" != "" ] && echo "Cannot get an WAN address, will try and restart the VPN" | mail -s "Network Failure" ${EMAIL_NOTICE}
SENDNOTICE "Network Failure" "Cannot get an WAN address, will try and restart the VPN"
touch ${MMFOLDER}/mm.vpn.fail
MMSTOP
sleep 2m
@@ -225,7 +225,7 @@ PersistentKeepalive = 25" >> /etc/wireguard/wg-torguard.conf
echo -e "${idsCL[Red]}Traffic is not routing through VPN, restarting system!${idsCL[Default]}"
echo "$(date) - Traffic is not routing through VPN, restarting system! scip(${scip}) mmip(${mmip})" >> $logfile
[ $VERBOSE = true ] && echo "$(date) - Default Routes: zerogw(${zerogw}) defaultgw(${defaultgw})" >> $logfile
[ "${EMAIL_NOTICE}" != "" ] && echo "Traffic route failure, will try and restart the VPN" | mail -s "Network Failure" ${EMAIL_NOTICE}
SENDNOTICE "Network Failure" "Traffic route failure, will try and restart the VPN"
touch ${MMFOLDER}/mm.vpn.fail
MMSTOP
sleep 2m
@@ -261,7 +261,7 @@ PersistentKeepalive = 25" >> /etc/wireguard/wg-torguard.conf
fi
if [ "${EMAIL_NOTICE}" != "" ] && [ ${PMFS} = true ]; then
echo "Could not mount the Plex Media Folder" | mail -s "Plex Media Not Mounted" ${EMAIL_NOTICE}
SENDNOTICE "Plex Media Not Mounted" "Could not mount the Plex Media Folder"
touch ${MMFOLDER}/mm.plexmount.fail
echo "$(date) - Plex Media could not be mounted" >> $logfile
fi
@@ -294,7 +294,7 @@ PersistentKeepalive = 25" >> /etc/wireguard/wg-torguard.conf
fi
if [ -f ${MMFOLDER}/mm.vpn.fail* ]; then
echo "$(date) - VPN issue has been fixed" >> $logfile
[ "${EMAIL_NOTICE}" != "" ] && echo "VPN issue has been fixed" | mail -s "Services Restored" ${EMAIL_NOTICE}
SENDNOTICE "Services Restored" "VPN issue has been fixed"
rm -f ${MMFOLDER}/mm.vpn.fail*
fi
rm -f ${MMFOLDER}/mm.stop*
@@ -500,7 +500,7 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
/bin/kill $i
done
echo "$(date) - Bash script stuck in stop mode after doing a check" >> $logfile
[ "${EMAIL_NOTICE}" != "" ] && echo "Bash script stuck in stop mode after doing a check" | mail -s "MM Script Error" ${EMAIL_NOTICE}
SENDNOTICE "MM Script Error" "Bash script stuck in stop mode after doing a check"
else
exit 1
fi