qdm12 / gluetun

VPN client in a thin Docker container for multiple VPN providers, written in Go, and using OpenVPN or Wireguard, DNS over TLS, with a few proxy servers built-in.
https://hub.docker.com/r/qmcgaw/gluetun
MIT License
7.34k stars 348 forks source link

Feature request: active connection quality monitoring for all VPN providers but especially Mullvad, restart if connection stops working #1605

Open tonsimple opened 1 year ago

tonsimple commented 1 year ago

What's the feature 🧐

Basically, sometimes VPNs start developing odd slowdowns / straight up hangs. It happens to me on Mullvad without gluetun too (as in just my regular router).

Usually that's not a problem and I can restart it manually (also it happens like twice a week so actually pinning down the cause is going to prove very time-consuming)

But soon I intend to use gluetun in a largely unattended system (where manually restarting would prove rather hard if not impossible) and jerry-rigging a monitoring-and-restart solution for VPN/gluetun is proving trickier than I expected.

If such a feature were to be included in gluetun itself it would be massively helpful

f0oster commented 1 year ago

Gluetun has a control server which exposes a HTTP API.

You can send commands to the control server to restart the VPN connection. You can also query the connection status, although I don't think any performance metrics are reported.

HTTP PUT to /v1/openvpn/status with a body {"status":"stopped"} to stop Openvpn
HTTP PUT to /v1/openvpn/status with a body {"status":"running"} to start Openvpn

You can either build and run a simple docker container that runs a cronjob to restart OpenVPN periodically, or you can run a cronjob on the docker host instead.

An untested example:

#!/bin/bash

START_API_ENDPOINT="http://localhost:port/v1/openvpn/status"
STOP_API_ENDPOINT="http://localhost:port/v1/openvpn/status"

START_REQUEST_BODY='{"status":"running"}'
STOP_REQUEST_BODY='{"status":"stopped"}'

curl -X PUT -H "Content-Type: application/json" -d "$STOP_REQUEST_BODY" "$STOP_API_ENDPOINT"
sleep 10
curl -X PUT -H "Content-Type: application/json" -d "$START_REQUEST_BODY" "$START_API_ENDPOINT"