From 51d6d36404ae7bd5cf8ee72d2355e03569c65092 Mon Sep 17 00:00:00 2001 From: Ruben Barkow Date: Fri, 12 May 2017 21:45:34 +0200 Subject: [PATCH 1/2] try restart openvpn if interface is missing --- files/usr/local/bin/check-gateway | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/files/usr/local/bin/check-gateway b/files/usr/local/bin/check-gateway index 0d7f8d3..61d2f45 100755 --- a/files/usr/local/bin/check-gateway +++ b/files/usr/local/bin/check-gateway @@ -45,10 +45,19 @@ if [[ $MAINTENANCE -eq 0 ]]; then /sbin/ip rule add from all fwmark 0x1 unreachable preference 32001 fi - # check for interface + # try restart openvpn if interface is missing /sbin/ip link show dev "${GW_INTERFACE}" > /dev/null 2>&1 if [[ $? -gt 0 ]] then + logger -t check-gatway -p daemon.info -s "Interface $GW_INTERFACE does not exist, try restart" + /usr/sbin/service openvpn restart + fi + + # check again for interface + /sbin/ip link show dev "${GW_INTERFACE}" > /dev/null 2>&1 + if [[ $? -gt 0 ]] + then + # count missing states and restart after $INTERFACE_MISSING minutes INTERFACE_MISSING=$(cat "$INTERFACE_MISSING_STATE" 2>/dev/null || echo 0) echo $(( INTERFACE_MISSING + 1)) > "$INTERFACE_MISSING_STATE" logger -t check-gateway -p daemon.info "Interface $GW_INTERFACE does not exist, for $INTERFACE_MISSING minutes." From b39260363265c4ef3b0538ce10720e46f93e21fc Mon Sep 17 00:00:00 2001 From: rubo77 Date: Wed, 31 May 2017 18:33:25 +0200 Subject: [PATCH 2/2] stop and start openvpn instead of restart --- files/usr/local/bin/check-gateway | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/files/usr/local/bin/check-gateway b/files/usr/local/bin/check-gateway index 61d2f45..2d1741a 100755 --- a/files/usr/local/bin/check-gateway +++ b/files/usr/local/bin/check-gateway @@ -45,15 +45,7 @@ if [[ $MAINTENANCE -eq 0 ]]; then /sbin/ip rule add from all fwmark 0x1 unreachable preference 32001 fi - # try restart openvpn if interface is missing - /sbin/ip link show dev "${GW_INTERFACE}" > /dev/null 2>&1 - if [[ $? -gt 0 ]] - then - logger -t check-gatway -p daemon.info -s "Interface $GW_INTERFACE does not exist, try restart" - /usr/sbin/service openvpn restart - fi - - # check again for interface + # check for openvpn interface and try to restart if interface is missing /sbin/ip link show dev "${GW_INTERFACE}" > /dev/null 2>&1 if [[ $? -gt 0 ]] then @@ -67,6 +59,9 @@ if [[ $MAINTENANCE -eq 0 ]]; then /usr/local/bin/maintenance on exit 1 fi + logger -t check-gatway -p daemon.info -s "restart openvpn" + /usr/sbin/service openvpn stop + /usr/sbin/service openvpn start else echo 0 > "${INTERFACE_MISSING_STATE}" fi