Skip to content

Conversation

@juanlufont
Copy link

@juanlufont juanlufont commented Dec 1, 2024

The script transmission-port-update.sh updates the peer port used by the torrent client Transmission using its API. The peer port is the port used and announced by Transmission to accept incoming connections. You can use this script to set a VPN forwarded port as the current listening port for Transmission.

The script uses only shell scripting and can run out of the box within the current gluetun docker image, it only relies on the command wget, which is already included by default in the image.

The script `transmission-port-update.sh` updates the _peer port_ used by
the torrent client Transmission. The peer port is the port used and
announced by Transmission to accept incoming connections.
@ku1ik
Copy link

ku1ik commented Dec 28, 2024

I've used this script and it worked on the first try. Thank you!

@ku1ik
Copy link

ku1ik commented Jan 22, 2025

Just reporting that I've been using this for over a month and it's been working flawlessly 👌

- better error handling
- support for comma-separated list of ports (use only first one)
- style corrections
- improved messages
Copy link
Owner

@qdm12 qdm12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review of the PR (and the wiki PR 👍 ) Just a few minor things to do if possible 🙏 thanks!

fi

echo "Success! Transmission peer-port updated to ${PORT}"
exit 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the final exit 😉 (afaik)

Suggested change
exit 0

@iridial
Copy link

iridial commented Mar 8, 2025

I did some tests in k3s with gluetun v3.40 running as initContainer for transmission, and using VPN_PORT_FORWARDING_UP_COMMAND as trigger to call the script using: '/bin/sh -c "/scripts/transmission-port-update.sh --port {{PORTS}}"'.
The transmission container takes more time to be available to receive the port forward update request, and this leads the initial call of the script to fail.
I suggest to include an initial check if transmission api service is available, and if not, retry once more after configurable timeout with /bin/sleep <value>.

@sboger

This comment was marked as off-topic.

@qdm12
Copy link
Owner

qdm12 commented Nov 13, 2025

The transmission container takes more time to be available to receive the port forward update request, and this leads the initial call of the script to fail.

Let's add --retry-connrefused -t 3 to the wget command

@qdm12 qdm12 added the Status: 🔒 After next release Will be done after the next release label Nov 13, 2025
@qdm12 qdm12 changed the title Add script to update Transmission peer port feat(extras/scripts): update qBittorrent peer port Nov 13, 2025
Comment on lines +92 to +102
# get the X-Transmission-Session-Id
# shellcheck disable=SC2086
SESSION_ID=$(
wget \
--quiet \
${WGET_OPTS} \
--server-response \
"$RPC_URL" 2>&1 |
grep 'X-Transmission-Session-Id:' |
awk '{print $2}'
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider wrapping this in a loop, which fails after some retries:

i=1
while [ "$i" -le $MAX_RETRIES ]; do
    # get the X-Transmission-Session-Id
    # shellcheck disable=SC2086
    SESSION_ID=$(
        wget \
            --quiet \
            ${WGET_OPTS} \
            --server-response \
            "$RPC_URL" 2>&1 |
            grep 'X-Transmission-Session-Id:' |
            awk '{print $2}'
    )
    
    if [ -n "$SESSION_ID" ]; then
        echo "Transmission available. SESSION_ID: $SESSION_ID"
        break
    else
        echo "Attempt $i of $MAX_RETRIES failed, waiting for next attempt..."
        sleep 5
    fi

    i=$(( i + 1 ))
done

@qdm12 qdm12 changed the title feat(extras/scripts): update qBittorrent peer port feat(extras/scripts): update Transmission peer port Nov 14, 2025
exit 1
fi

echo "Success! Transmission peer-port updated to ${PORT}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
echo "Success! Transmission peer-port updated to ${PORT}"
echo "Transmission peer-port updated to ${PORT}"

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants