diff --git a/mm-scripts.sh b/mm-scripts.sh index e4c01b0..e396fef 100755 --- a/mm-scripts.sh +++ b/mm-scripts.sh @@ -30,60 +30,39 @@ MMSTART(){ echo echo -en "${idsCL[LightCyan]}Starting the VPN Tunnel ... ${idsCL[Default]}" "${VPN_START[@]}" - sleep 3s + sleep 5s else mmsv='Verifying' fi - checked=false - cc=0 - until [ "${checked}" = "" ]; do - OUT=$(ip link | grep "$VPN_INTERFACE") - #OUT=`ip a show $VPN_INTERFACE up` >/dev/null 2>&1 - if [ ${#OUT} -ne 0 ]; then - checked="" - elif [ "${1}" = "check" ] && [ ${cc} -eq 0 ]; then + OUT=$(ip link | grep "$VPN_INTERFACE") + if [ ${#OUT} = 0 ]; then + if [ -f /opt/mm.vpn.fail ]; then + echo -e "${idsCL[Red]} failed, restarting system${idsCL[Default]}" + echo "$(date) - VPN Failure #2 - restarting system" >> $logfile + touch /opt/mm.vpn.fail2 + rm -f /opt/mm.vpn.fail + MMSTOP + sleep 5m + "${VPN_START[@]}" + rm -f /opt/mm.stop + exit 1 + elif [ -f /opt/mm.vpn.fail2 ]; then + echo "$(date) - VPN Failure #3 - Shutting down Media Management systems" >> $logfile + MMSTOP + exit 1 + else + echo -e "${idsCL[Red]} failed, restarting system${idsCL[Default]}" + echo "$(date) - VPN Failure #1 - restarting system" >> $logfile touch /opt/mm.vpn.fail - echo "$(date) - VPN Failure on 1st check" >> $logfile MMSTOP sleep 1m "${VPN_START[@]}" rm -f /opt/mm.stop exit 1 fi - if [ "${checked}" == "false" ] && [ ${cc} -eq 10 ]; then - if [ -f /opt/mm.vpn.fail ]; then - echo "$(date) - VPN Failure #2" >> $logfile - touch /opt/mm.vpn.fail2 - rm -f /opt/mm.vpn.fail - MMSTOP - sleep 5m - "${VPN_START[@]}" - rm -f /opt/mm.stop - exit 1 - elif [ -f /opt/mm.vpn.fail2 ]; then - echo "$(date) - VPN Failure #3 - Shutting down Media Management systems" >> $logfile - MMSTOP - exit 1 - else - echo "$(date) - VPN Failure #1" >> $logfile - touch /opt/mm.vpn.fail - MMSTOP - sleep 1m - "${VPN_START[@]}" - rm -f /opt/mm.stop - exit 1 - fi - fi - ((cc=${cc}+1)) - sleep 1s - done - - - OUT=$(ip link | grep "$VPN_INTERFACE") - #OUT=`ip a show $VPN_INTERFACE up` >/dev/null 2>&1 - if [ ${#OUT} -ne 0 ]; then + else if [ "$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)" != "$(ip route show | grep default | cut -d' ' -f 3)" ]; then /bin/ip route del default via 10.10.0.1