I get the same exact issue with gluetun! Such a pain in the ass though sometimes mine will not come back up.
The only way I can see accomplishing this would be having a down connection trigger some custom code that renames another server .conf file to wg0.conf
I couldn't get the webserver to come up on failure without adding nginx and changing what Dockerfile's CMD pointed at _AND_ adding exec commands to various files. I did get it t work with nginx, but I gave up when trying to use the supplied python core to remove the addition of nginx. Since I didn't want to do half of that, I consider my modifications trash.
I did write a script to rotate confs. Although it can rotate regular files too, the comments/references are oriented at the usage with this container. There's a limited test file as well (~65% coverage).
Note: the zip comes with a supplied "start.sh", but that also adds 3 lines that create a "vpn_down" file when the vpn is seemingly down and deletes it on a successful health check.
Usage:
#
# Rotates files with or without an interval.
#
# This was tested with: https://github.com/DyonR/docker-qbittorrentvpn
# Prebuilt at: https://hub.docker.com/r/dyonr/qbittorrentvpn/
#
#
# Usage:
#
# 1. Build and start the container.
#
# 2. Stop the container and edit the container specs to mount start.sh.
#
# ie. -v "$containers/config/qbittorrent/start.sh":/etc/qbittorrent/start.sh
#
# 3. In the "if [[ "${STATUS}" -ne 0 ]]; then" statement at the bottom add:
#
# if [[ ! -z ${ROTATE_INTERVAL} ]]; then
# /bin/bash /config/rotate_vpn.bash "$VPN_TYPE" "$ROTATE_INTERVAL" \
# "$ROTATE_CONFS_DIR" "$ROTATE_CONFIG_DIR" "$ROTATE_OG_NAME";
# fi
#
# (look at the bottom for help on getting start.sh)
#
# 4. Define a variable named "ROTATE_INTERVAL" in your docker specs.
#
# eg. -e "ROTATE_INTERVAL=0" (# = amount of bad health checks to wait)
#
# 5. Make the directory "/config/vpn_confs" and put your vpn confs in it.
#
# 6. Put a vpn conf in the required directory as normal so the container
# starts properly. Put only 1 conf in if using openvpn, also read the note.
# NOTE: If using openvpn, use the name "default.ovpn", since the script
# doesn't use rm, it had to be static name.
#
# 7. Restart the container.
#
# The contents of the "/config" directoy should read as:
# "/config/qbittorrent/"
# "/config/wireguard/" (or "/config/openvpn")
# "/config/vpn_confs/"
# "/config/rotate_vpn.bash"
#
# Parameters:
# $1: VPN_TYPE : string
# Default: "wireguard"
# NOTE: VPN_TYPE is supplied via the container script, it only needs to be
# given if running this outside the container or if the container doesn't
# supply it. In contrast to this, the container's default is "openvpn".
# 2 options only, "wireguard" or "openvpn".
# (there'as an exception for ROTATE_OG_NAME, see below)
# $2: ROTATE_INTERVAL : integer
# Default: 0, 0 = rotate on every FAILED health check
# Count of health checks that must FAIL before rotation until a VPN
# conf is rotated.
# $3: ROTATE_CONFS_DIR : string
# Default: "/config/vpn_confs"
# Directory with all VPN confs eg. "/config/vpn_confs".
# $4: ROTATE_CONFIG_DIR : string
# Default: "/config"
# This is the location of the ".rotation" file and where the VPN_TYPE
# directory is located. eg. if VPN_TYPE is "wireguard", then the
# directory "/config/wireguard" will be next to the ROTATION_FILE,
# "/config/.rotation".
# $5: ROTATE_OG_NAME : integer (Optional)
# Default: 0 (no), 1 = yes, 0 = no
# Use the original file name on copy, not "wg0.conf" or default.ovpn.
# A value of 1 means yes, "do use the original filename".
# Note that when ROTATE_OG_NAME is 1 (yes), then VPN_TYPE can
# be set to anything. You could set VPN_TYPE to "Documents" and if
# ROTATE_CONFIG_DIR is set to "/home/me", then this cp could be done:
# cp -f "/config/vpn_confs/some.file" "/home/me/Documents/some.file"
# Return:
# 0: when nothing has happened
# 1: on error
# 2: on success of rotating a VPN conf
# Artifacts:
# - "$ROTATE_CONFIG_DIR/.rotation"
# If interval is > 0, a file named ".rotation" is created in the
# ROTATE_CONFIG_DIR to perserve count across restarts. The ".rotation"
# file will have the required $ROTATE_INTERVAL and a count of how many
# times the vpn conf has been rotated. The file has the below 2 entries:
# rotation_interval,4
# rotation_count,n
# Interval is required, but only a warning if the count fails to update
# If ROTATE_INTERVAL is 0, only the line "rotation_count,n" will exist
# - "/config/openvpn/default.ovpn"
# When using "openvpn" as VPN_TYPE, the VPN file is copied from
# ROTATE_CONFS_DIR to the "/config/openvpn" directory as "default.ovpn"
# - "/config/wireguard/wg0.conf", the wireguard equivalent of "default.ovpn"
# Help:
# The directories "/cofig/wireguard" and "/config/openvpn" should only
# ever have 1 VPN conf file in them at any time so that the newest file is
# always loaded.
#
# ROTATE_INTERVAL is in tandum with HEALTH_CHECK_INTERVAL.
# Everytime a _FAILED_ health check files, the script is called. Once the
# script has executed the amount of times assigned to ROTATE_INTERVAL, the
# script rotates a VPN conf. So if a _FAILED_ health check happens every 30
# seconds and ROTATE_INTERVAL is set to 4, a VPN conf is rotated every 2
# minutes. If ROTATE_INTERVAL is set to 0 (zero), then VPN conf is rotated
# at every _FAILED_ health check. So, if HEALTH_CHECK_INTERVAL is set to
# 30 secs., and the check always fails, a rotation happens every 30 seconds.
#
# This was scripted for a specific Docker container but, to use it for
# something else, here's some help with that. Call the script like this:
#
# /bin/bash ./rotate_vpn_conf.bash ${VPN_TYPE} ${ROTATE_INTERVAL} ${ROTATE_CONFS_DIR} ${ROTATE_CONFIG_DIR}
# ie.
# /bin/bash ./rotate_vpn_conf.bash "wireguard" "4" "/home/me/vpn_confs" "/home/me"
#
# The ROTATE_CONFIG_DIR, "/home/me" in the above example, is where the file
# ".rotation" will be created and used. The ROTATE_CONFS_DIR directory,
# "/home/me/vpn_confs" in the above example, can be anywhere. "/home/me"
# needs to be writeable, "/home/me/vpn_confs" doesn't need to be writeable.
#
# IF you want to stop using an interval and go back to 0, which is to rotate
# on every failed health check, remove the line "rotation_interval,n" from
# the ".rotation" file. This might help container users. Effectively, this
# this script simply copies a file to another directory with error handling,
# based on an interval.
#
# If you need a copy of "start.sh", log into your container with:
# sudo docker exec -it qbittorrent bash
# then
# cp /etc/qbittorrent/start.sh /configure
Alles anzeigen