From 265944f236caa9535c3b86ec0c6aa05587d9232d Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sat, 25 Mar 2023 09:14:48 -0500 Subject: [PATCH] Update mm-scripts.sh --- mm-scripts.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/mm-scripts.sh b/mm-scripts.sh index 1949e6e..84f4123 100755 --- a/mm-scripts.sh +++ b/mm-scripts.sh @@ -240,6 +240,7 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf fi + echo -en "${idsCL[LightCyan]}Verifying Plex Media is Mounted : ${idsCL[Default]}" ### CHECK FOR PLEX MOUNT files=$(shopt -s nullglob dotglob; echo ${PLEX_MOUNT}/*) if (( ! ${#files} )); then @@ -255,7 +256,6 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf fd=$(( `date +%s` - `stat -L --format %Y ${MMFOLDER}/mm.plexmount.fail` )) if [ ${fd} -gt 3600 ]; then PMFS=true - rm -f ${MMFOLDER}/mm.plexmount.fail else PMFS=false fi @@ -265,21 +265,29 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf if [ "${EMAIL_NOTICE}" != "" ] && [ ${PMFS} = true ]; then SENDNOTICE "Plex Media Not Mounted" "Could not mount the Plex Media Folder" 1 - touch ${MMFOLDER}/mm.plexmount.fail echo "$(date) - Plex Media could not be mounted" >> $logfile fi + touch ${MMFOLDER}/mm.plexmount.fail + echo -e "${idsCL[Red]}Not Mounted, stopping services${idsCL[Default]}" + for srvc in "${SERVICES_CHECK[@]}"; do + /bin/systemctl stop ${srvc} + done + else + echo -e "${idsCL[Green]}Mounted, fixed${idsCL[Default]}" + rm -f ${MMFOLDER}/mm.plexmount.fail echo "$(date) - Plex Media now mounted, stopping services to restart them" >> $logfile for srvc in "${SERVICES_CHECK[@]}"; do /bin/systemctl stop ${srvc} done fi else + echo -e "${idsCL[Green]}Mounted${idsCL[Default]}" rm -f ${MMFOLDER}/mm.plexmount.fail fi [ "${1}" == "start" ] && rm -f ${MMFOLDER}/mm.noservices - if [ "${2}" != "vpn" ] && [ ! -f ${MMFOLDER}/mm.noservices ]; then + if [ "${2}" != "vpn" ] && [ ! -f ${MMFOLDER}/mm.noservices ] && [ ! -f ${MMFOLDER}/mm.plexmount.fail ]; then echo -en "${idsCL[LightCyan]}${mmsv} Services :${idsCL[Default]}" for srvc in "${SERVICES_CHECK[@]}"; do /bin/systemctl start ${srvc} @@ -287,7 +295,6 @@ PersistentKeepalive = 25" >> /etc/wireguard/${VPN_INTERFACE}.conf echo -e "${idsCL[Green]} done${idsCL[Default]}" else echo -e "${idsCL[LightYellow]}Skipping ${mmsv} Services ${idsCL[Default]}" - touch ${MMFOLDER}/mm.noservices fi echo @@ -402,13 +409,20 @@ MMSTATUS(){ echo -en " ${NM_SERVICES[${srvc}]}$spc: " if [ "$(systemctl is-active ${srvc})" != "active" ] && [ "${srvc}" != "wireguard" ]; then - echo -e "${idsCL[Red]}Not Running${idsCL[Default]}" + if [ ! -f ${MMFOLDER}/mm.noservices ] && [ ! -f ${MMFOLDER}/mm.plexmount.fail ]; then + echo -e "${idsCL[Red]}Not Running${idsCL[Default]}" + elif [ ! -f ${MMFOLDER}/mm.noservices ]; then + echo -e "${idsCL[Red]}Skipping, started wtih VPN only${idsCL[Default]}" + elif [ ! -f ${MMFOLDER}/mm.plexmount.fail ]; then + echo -e "${idsCL[Red]}Skipping, Plex Media not mounted${idsCL[Default]}" + fi elif [ "${srvc}" == "wireguard" ] && [ "$(/sbin/ip link | grep $VPN_INTERFACE)" == "" ]; then echo -e "${idsCL[Red]}Not Running${idsCL[Default]}" else echo -e "${idsCL[Green]}Running${idsCL[Default]}" + if [[ ${srvc} == *"vpn"* ]] || [[ ${srvc} == *"wireguard"* ]]; then zerogw=$(/sbin/ip route show | grep 0.0.0.0 | cut -d' ' -f 3) defaultgw=$(/sbin/ip route show | grep default | cut -d' ' -f 3) @@ -472,6 +486,9 @@ MMSTATUS(){ fi echo + + else + fi fi