ich777 / docker-openvpn-client

GNU Affero General Public License v3.0
6 stars 5 forks source link

Restart on multiple failed pings #15

Closed ItalyToast closed 1 month ago

ItalyToast commented 1 month ago

I've tried changing the script start-ping.sh to restart the VPN on 2 failed pings in a row. It cant find the start.sh script when I try to launch it in uraid.

Could you add it as a feature or maybe you could help me to get it to build correctly?

I build it on windows with wsl2.

#!/bin/bash
sleep 10
fail_count=0  # Initialize fail counter

while true; do
  if ! ping -c 1 -W 10 ${PING_IP} >/dev/null 2>&1 ; then
    fail_count=$((fail_count + 1))  # Increment the failure counter
    echo "---Ping from ${PING_IP} failed (${fail_count}/2), checking again...---"
    if [ ${fail_count} -ge 2 ]; then  # Check if 2 consecutive failures occurred
      echo "---2 consecutive pings failed, restarting container...---"
      kill -SIGKILL $(pidof openvpn)
      fail_count=0  # Reset fail counter after restarting
    fi
  else
    fail_count=0  # Reset the failure counter on a successful ping
  fi
  sleep ${PING_INTERVAL}s
done

^ this is the script I've used in start-ping.sh

ich777 commented 1 month ago

@ItalyToast why do you need ping in the first place? The container or better speaking OpenVPN does usually re-establish the connection on it‘s own.

I just implemented the ping check on user request but I never understod why this is even necessary because OpenVPN does in fact re connect.

ItalyToast commented 1 month ago

I assumed the ping check was the mechanism for keeping the container online. My issue is that the ping fails a couple of times a day and is causing restarts. I guess I can try disabling the ping check altogether and it should still work?

ich777 commented 1 month ago

I assumed the ping check was the mechanism for keeping the container online. My issue is that the ping fails a couple of times a day and is causing restarts. I guess I can try disabling the ping check altogether and it should still work?

Yes it should work if you disable the ping check all together, so to speak remove the IP for the ping check.

ItalyToast commented 1 month ago

Update: The VPN havent gone down in 2 days.

ich777 commented 1 month ago

You mean the container didn't restart on it's own because of ping? I think OpenVPN handles that way better than the ping solution that I've implemented.

ItalyToast commented 1 month ago

Yes, ping caused the restarts. Works way better now without the ping "feature". Since ping is affected by packet loss as soon as a ping packet is dropped the container would restart. All the containers connected to the vpn havent stopped in 47h. Since I want to inspect the container that crashes this have saved me a bunch of work 👍

I would suggest disabling the ping feature by default.