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: ddwrt-ovpn-server-watchdog.sh
- # version: 1.2.0, 02-oct-2024, by eibgrad
- # purpose: (re)start failed/stopped openvpn server
- # script type: startup (autostart)
- # installation:
- # 1. enable jffs2 (administration->jffs2)
- # 2. enable syslogd (services->services->system log)
- # 3. use shell (telnet/ssh) to execute one of the following commands:
- # curl -kLs bit.ly/ddwrt-installer|tr -d '\r'|sh -s -- 4QyiANWh startup
- # or
- # wget -qO - bit.ly/ddwrt-installer|tr -d '\r'|sh -s -- 4QyiANWh startup
- # 4. (optional): use vi editor to modify options:
- # vi /jffs/etc/config/ddwrt-ovpn-server-watchdog.startup
- # 5. reboot
- (
- # ------------------------------ BEGIN OPTIONS ------------------------------- #
- # time (in secs) between checks for failed/stopped openvpn server
- CHECK_INTERVAL=60
- # ------------------------------- END OPTIONS -------------------------------- #
- # ---------------------- DO NOT CHANGE BELOW THIS LINE ----------------------- #
- LOCK="/tmp/$(basename $0).lock"
- OVPN_CONF='/tmp/openvpn/openvpn.conf'
- # 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
- # openvpn server must be enabled
- [ "$(nvram get openvpn_enable)" != '0' ] || continue
- # check for failed/stopped openvpn server
- [ "$(ps | awk '$0~v{print $1}' v="--config +$OVPN_CONF")" ] && continue
- # fall-through means failure; restart the openvpn server
- stopservice openvpnserver && sleep 5
- startservice openvpnserver && sleep 5
- echo "info: openvpn server (re)started @ $(date)"
- done
- ) 2>&1 | logger -t "$(basename $0) | grep -Eo '^.{0,23}')[$$]" &
Add Comment
Please, Sign In to add comment