Enhance gluetun PIA WireGuard rotator with improved rate limit handling and retry logic. Update README to document new RATE_LIMIT_WAIT_SECONDS variable for managing retries after PIA rate limits.
Build and Push Docker Images / build-and-push (push) Successful in 49s
Build and Push Docker Images / build-and-push (push) Successful in 49s
This commit is contained in:
@@ -130,6 +130,31 @@ write_state() {
|
||||
chmod 644 "$state_path"
|
||||
}
|
||||
|
||||
# EX_TEMPFAIL — entrypoint retries after RATE_LIMIT_WAIT_SECONDS
|
||||
readonly EXIT_RATE_LIMITED=75
|
||||
|
||||
generate_wg_config() {
|
||||
local region="$1"
|
||||
local out="$2"
|
||||
local output rc=0
|
||||
|
||||
# Capture stdout+stderr so we can detect PIA 429 rate limits.
|
||||
output="$(pia-wg-config -v -r "$region" -o "$out" "$PIA_USER" "$PIA_PASS" 2>&1)" || rc=$?
|
||||
printf '%s\n' "$output" >&2
|
||||
|
||||
if ((rc == 0)); then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$output" == *"too_many_attempts"* || "$output" == *"status 429"* ]]; then
|
||||
>&2 echo "pia-wg-config rate-limited for region=$region"
|
||||
return "$EXIT_RATE_LIMITED"
|
||||
fi
|
||||
|
||||
>&2 echo "pia-wg-config failed for region=$region"
|
||||
return 1
|
||||
}
|
||||
|
||||
rotate_once() {
|
||||
require_env PIA_USER
|
||||
require_env PIA_PASS
|
||||
@@ -146,10 +171,7 @@ rotate_once() {
|
||||
|
||||
local tmp_conf="${tmp_dir}/wg0.conf"
|
||||
log "Generating WireGuard config with pia-wg-config"
|
||||
if ! pia-wg-config -v -r "$region" -o "$tmp_conf" "$PIA_USER" "$PIA_PASS"; then
|
||||
>&2 echo "pia-wg-config failed for region=$region"
|
||||
exit 1
|
||||
fi
|
||||
generate_wg_config "$region" "$tmp_conf"
|
||||
|
||||
if ! grep -q '^\[Interface\]' "$tmp_conf"; then
|
||||
>&2 echo "Generated config missing [Interface] section"
|
||||
|
||||
Reference in New Issue
Block a user