eibgrad

ddwrt-ovpn-watchdog.sh

Apr 10th, 2021 (edited)
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. DEBUG=; set -x # uncomment/comment to enable/disable debug mode
  3.  
  4. #          name: ddwrt-ovpn-watchdog.sh
  5. #       version: 1.0.1, 19-apr-2021, by eibgrad
  6. #       purpose: (re)start failed/stopped openvpn client
  7. #   script type: startup (autostart)
  8. #  installation:
  9. #    1. enable jffs2 (administration->jffs2)
  10. #    2. enable syslogd (services->services->system log)
  11. #    3. use shell (telnet/ssh) to execute one of the following commands:
  12. #         curl -kLs bit.ly/ddwrt-installer|tr -d '\r'|sh -s -- iNC273ER startup
  13. #       or
  14. #         wget -qO - bit.ly/ddwrt-installer|tr -d '\r'|sh -s -- iNC273ER startup
  15. #    4. (optional): use vi editor to modify options:
  16. #         vi /jffs/etc/config/ddwrt-ovpn-watchdog.startup
  17. #    5. reboot
  18. (
  19. # ------------------------------ BEGIN OPTIONS ------------------------------- #
  20.  
  21. # time (in secs) between checks for failed/stopped openvpn client
  22. INTERVAL=20
  23.  
  24. # ------------------------------- END OPTIONS -------------------------------- #
  25.  
  26. # ---------------------- DO NOT CHANGE BELOW THIS LINE ----------------------- #
  27.  
  28. # wait for *reliable* internet connection
  29. while ! ping -qc1 -w3 8.8.8.8 >/dev/null 2>&1; do sleep 10; done
  30.  
  31. while :; do
  32.     if [ "$(nvram get openvpncl_enable)" != "0" ]; then
  33.         if ! ps | grep -q [o]penvpncl && [ -f $OVPN_CONF ]; then
  34.             openvpn --config /tmp/openvpncl/openvpn.conf --daemon
  35.             echo "openvpn (re)started @ $(date)"
  36.         fi
  37.     fi
  38.  
  39.     sleep $INTERVAL
  40. done
  41.  
  42. ) 2>&1 | logger -p user.$([ ${DEBUG+x} ] && echo 'debug' || echo 'notice') \
  43.     -t $(echo $(basename $0) | grep -Eo '^.{0,23}')[$$] &
RAW Paste Data