[alpine-devel] openvpn: check tunnel patch

Ilya Strelkin
Details
Message ID
<be249ad40902180400l356cc7d9v66f6553dde7909ff@mail.gmail.com>
Sender timestamp
1234958426
DKIM signature
missing
Download raw message
Hi!

Here is the patch for /etc/init.d/openvpn script to check if tunnel is up
before going any further

1. new /etc/conf.d/openvpn file is required

# Suspend processing until tunnel is connected
SUSPEND_UNTIL_CONNECTED=YES

# Probe IP to check tunnel connectivity
PROBE_IP=192.168.0.1

2. /etc/init.d/openvpn patch
--- openvpn     Wed Feb 18 11:26:58 2009
+++ openvpn-new Wed Feb 18 11:28:13 2009
@@ -52,7 +52,29 @@
        start-stop-daemon --start --exec /usr/sbin/openvpn --pidfile
"${VPNPID}" \
                -- --config "${VPNCONF}" --writepid "${VPNPID}" --daemon
${args}

+       R=$?
        eend $? "Check your logs to see why startup failed"
+
+       #iilluzion: Check if tunnel is up but no longer than 1 minute
+       if [ "$SUSPEND_UNTIL_CONNECTED" = "YES" -a $R -eq 0 ]; then
+               ebegin "Waiting for tunnel is up (max 1 min)"
+                       PROBE_IP=${PROBE_IP:-10.8.0.1}
+                       COUNT=0
+                       while true; do
+                               echo -n "."
+                               ping -W 2 -w 3 -c 1 -q $PROBE_IP > /dev/null
2>&1
+                               R=$?
+                               if [ $R -eq 0 ]; then
+                                       break
+                               else
+                                       COUNT=$((COUNT + 1))
+                                       if [ $COUNT -gt 29 ]; then
+                                               break
+                                       fi
+                               fi
+                       done
+               eend $R "Check your logs to see why tunnel failed"
+       fi
 }

 stop() {