Skip to content

Commit

Permalink
stop and start openvpn instead of restart
Browse files Browse the repository at this point in the history
  • Loading branch information
rubo77 committed May 31, 2017
1 parent 51d6d36 commit 2c102d6
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions files/usr/local/bin/check-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,23 @@ if [[ $MAINTENANCE -eq 0 ]]; then
/sbin/ip rule add from all fwmark 0x1 unreachable preference 32001
fi

# try restart openvpn if interface is missing
# 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
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."
if [[ "$INTERFACE_MISSING" -gt "$MAX_INTERFACE_MISSING" ]]
then
logger -t check-gatway -p daemon.info -s "Interface $GW_INTERFACE does not exist, for longer than $MAX_INTERFACE_MISSING. Going into maintenance."
/usr/local/bin/maintenance on
exit 1
fi
# 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."
if [[ "$INTERFACE_MISSING" -gt "$MAX_INTERFACE_MISSING" ]]
then
logger -t check-gatway -p daemon.info -s "Interface $GW_INTERFACE does not exist, for longer than $MAX_INTERFACE_MISSING. Going into maintenance."
/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
Expand Down

0 comments on commit 2c102d6

Please sign in to comment.