Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request/Question: Multiple wireguard config files ? #2373

Open
TheRealBix opened this issue Jul 28, 2024 · 4 comments
Open

Feature request/Question: Multiple wireguard config files ? #2373

TheRealBix opened this issue Jul 28, 2024 · 4 comments

Comments

@TheRealBix
Copy link

What's the feature 🧐

Currently gluetun is able to switch between openvpn servers on unhealthy states (right now I use SERVER_HOSTNAMES setting to achieve this with cherry picked servers. Would it be possible to do the same with wireguard config files like wg0.conf, wg1.conf etc..
Or maybe there's already a way to do this I'm unaware of ?

Extra information and references

No response

Copy link
Contributor

@qdm12 is more or less the only maintainer of this project and works on it in his free time.
Please:

@skedastically
Copy link

I found a hacky way to do this by symlinking a different .conf file to wg0.conf before executing the /gluetun-entrypoint binary. This requires redefining the entrypoint command to run a shell script, and restarting your container when a defined healthcheck is triggered.

Suppose you have wireguard-01.conf, wireguard-02.conf, and wireguard-03.conf in your /gluetun/wireguard directory. Add the following script in /gluetun/startup.sh:

#!/bin/sh

WGCONF=/gluetun/wireguard/wg0.conf
# Unlinking the old wg0.conf
unlink $WGCONF

# Randomly choosing a new conf file from the wireguard* list
# For me this is enough
NEWCONF=$(ls /gluetun/wireguard/wireguard-*.conf | shuf -n 1)

# Make that the new wg0.conf
ln -T $NEWCONF $WGCONF

# Executing the binary

/gluetun-entrypoint

Then execute it on gluetun startup with the following docker-compose options:

services:
  gluetun:
    ...
    healthcheck:
      # If network is unreachable, exit 1 to indicate unhealthy container
      test: wget -O- https://ipinfo.io || exit 1
      # Tune these as needed
      interval: 20s
      timeout: 5s
      retries: 2
    
    # Run the shell script as the entrypoint
    entrypoint: '/bin/sh'
    command: '/gluetun/startup.sh'    

AFAIK Docker doesn't natively restart unhealthy containers, so feel free to use one of the following methods. For me a cron job would do.

@TheRealBix
Copy link
Author

That's a clever way i'll be happy to try, thanks !

@TheRealBix
Copy link
Author

TheRealBix commented Aug 1, 2024

Oops, it doesn't work...

ln: /gluetun/wireguard/wireguard-01.conf : No such file or directory
unlink: can't remove file '/gluetun/wireguard/wg0.conf ': No such file or directory

I sure have the wireguard folder and glutun volume mounted, when manually edited the wg0.conf is read by gluetun.
If you have a clue...

edit : newbie mistake, file was created on windows with CR+LF, the carriage return was the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants