never pick previous vpn
Build and Push Docker Images / build-and-push (push) Successful in 1m51s

This commit is contained in:
2026-07-29 19:21:36 +02:00
parent 151c2fcd8d
commit d7b6553eff
2 changed files with 28 additions and 3 deletions
@@ -100,7 +100,7 @@ Optioneel host-`.env`-keys (`WIREGUARD_*`) opruimen als die niet meer gebruikt w
1. Bij start: direct roteren (nieuwe config + container-restarts) 1. Bij start: direct roteren (nieuwe config + container-restarts)
2. Daarna: elke dag om `ROTATE_AT` opnieuw 2. Daarna: elke dag om `ROTATE_AT` opnieuw
3. Willekeurige region uit `PIA_REGIONS` 3. Willekeurige region uit `PIA_REGIONS`, nooit dezelfde als de vorige (uit `rotator-state.json`; uitzondering: maar één region geconfigureerd)
4. `GLUETUN_CONTAINER` wordt altijd als eerste herstart, daarna containers uit `RESTART_CONTAINERS` 4. `GLUETUN_CONTAINER` wordt altijd als eerste herstart, daarna containers uit `RESTART_CONTAINERS`
**Let op:** zet gluetun **niet** in `RESTART_CONTAINERS`; gebruik `GLUETUN_CONTAINER` daarvoor. Sidecars met `network_mode: service:...` horen in `RESTART_CONTAINERS`. **Let op:** zet gluetun **niet** in `RESTART_CONTAINERS`; gebruik `GLUETUN_CONTAINER` daarvoor. Sidecars met `network_mode: service:...` horen in `RESTART_CONTAINERS`.
@@ -27,8 +27,16 @@ parse_regions() {
tr ',' '\n' <<<"$raw" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | awk 'NF' tr ',' '\n' <<<"$raw" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | awk 'NF'
} }
read_previous_region() {
local state_path="${ROTATOR_STATE_PATH:-/config/rotator-state.json}"
if [[ ! -f "$state_path" ]]; then
return 0
fi
jq -r '.region // empty' "$state_path" 2>/dev/null || true
}
pick_random_region() { pick_random_region() {
local regions=() local regions=() previous candidates=()
while IFS= read -r region; do while IFS= read -r region; do
[[ -n "$region" ]] && regions+=("$region") [[ -n "$region" ]] && regions+=("$region")
done < <(parse_regions) done < <(parse_regions)
@@ -38,7 +46,24 @@ pick_random_region() {
exit 2 exit 2
fi fi
printf '%s\n' "${regions[@]}" | shuf -n 1 previous="$(read_previous_region)"
if [[ -n "$previous" ]]; then
for region in "${regions[@]}"; do
[[ "$region" == "$previous" ]] && continue
candidates+=("$region")
done
fi
if [[ "${#candidates[@]}" -eq 0 ]]; then
if [[ -n "$previous" && "${#regions[@]}" -eq 1 ]]; then
log "Only one region configured; reusing previous: $previous"
fi
candidates=("${regions[@]}")
else
log "Excluding previous region: $previous"
fi
printf '%s\n' "${candidates[@]}" | shuf -n 1
} }
parse_additional_restart_containers() { parse_additional_restart_containers() {