Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #DEBUG=; set -x # uncomment/comment to enable/disable debug mode
- # name: tomato-ovpn-server-watchdog.sh
- # version: 1.0.0, 07-oct-2024, by eibgrad
- # purpose: (re)start failed/stopped openvpn server(s)
- # script type: init (autostart)
- # installation:
- # 1. enable jffs (administration->jffs)
- # 2. enable syslog (status->logs->logging configuration->syslog)
- # 3. enable 'enable on start' option for openvpn server(s) to be monitored
- # 4. use shell (telnet/ssh) to execute one of the following commands:
- # curl -kLs bit.ly/tomato-installer|tr -d '\r'|sh -s -- tbQ1yAR0 init
- # or
- # wget -qO - bit.ly/tomato-installer|tr -d '\r'|sh -s -- tbQ1yAR0 init
- # 5. (optional) use vi editor to modify options:
- # vi /jffs/etc/config/tomato-ovpn-server-watchdog.init
- # 6. reboot
- (
- # ------------------------------ BEGIN OPTIONS ------------------------------- #
- # participating openvpn server(s) [ '1 2'=only | '*'=all | ''=none ]
- PARTICIPANTS='*'
- # time (in secs) between checks for failed/stopped openvpn server(s)
- CHECK_INTERVAL=60
- # ------------------------------- END OPTIONS -------------------------------- #
- # ---------------------- DO NOT CHANGE BELOW THIS LINE ----------------------- #
- LOCK="/tmp/$(basename $0).lock"
- # reject additional instances
- mkdir $LOCK &>/dev/null || exit 0
- # catch unexpected exit and cleanup
- trap "rmdir $LOCK; exit 0" SIGHUP SIGINT SIGTERM
- # wait for *reliable* internet connection
- until ping -qc1 -W3 8.8.8.8 &>/dev/null; do sleep 10; done
- while sleep $CHECK_INTERVAL; do
- # process all "enable on start" openvpn servers
- for i in $(nvram get vpn_server_eas | tr ',' ' '); do
- # confirm openvpn server is participant
- echo "$PARTICIPANTS" | grep -q "[*$i]" || continue
- pidof vpnserver${i} &>/dev/null && continue
- # fall-through means failure; restart the openvpn server
- service vpnserver${i} restart >/dev/null && sleep 5
- echo "info: openvpn server #$i (re)started @ $(date)"
- done
- done
- ) 2>&1 | logger -t "$(basename $0 | grep -Eo '^.{0,23}')[$$]" &
Add Comment
Please, Sign In to add comment