Skip to content

Commit

Permalink
Allow to disable WAN IP address (#150)
Browse files Browse the repository at this point in the history
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max and crazy-max authored Apr 28, 2022
1 parent fcb4fbb commit c76617e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 29 deletions.
80 changes: 55 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ___
* [Override or add a ruTorrent plugin/theme](#override-or-add-a-rutorrent-plugintheme)
* [Edit a ruTorrent plugin configuration](#edit-a-rutorrent-plugin-configuration)
* [Increase Docker timeout to allow rTorrent to shutdown gracefully](#increase-docker-timeout-to-allow-rtorrent-to-shutdown-gracefully)
* [WAN IP address](#wan-ip-address)
* [Upgrade](#upgrade)
* [Contributing](#contributing)
* [License](#license)
Expand Down Expand Up @@ -103,7 +104,8 @@ Image: crazymax/rtorrent-rutorrent:latest
* `TZ`: The timezone assigned to the container (default `UTC`)
* `PUID`: rTorrent user id (default `1000`)
* `PGID`: rTorrent group id (default `1000`)
* `WAN_IP`: Public IP address reported to the tracker (default auto resolved with `dig +short myip.opendns.com @resolver1.opendns.com`)
* `WAN_IP`: [Public IP address](#wan-ip-address) reported to the tracker.
* `WAN_IP_CMD`: Command to resolve the [Public IP address](#wan-ip-address) if `WAN_IP` empty. (`false` to disable ; default `dig +short myip.opendns.com @resolver1.opendns.com`)
* `MEMORY_LIMIT`: PHP memory limit (default `256M`)
* `UPLOAD_MAX_SIZE`: Upload max size (default `16M`)
* `CLEAR_ENV`: Clear environment in FPM workers (default `yes`)
Expand Down Expand Up @@ -172,8 +174,9 @@ Image: crazymax/rtorrent-rutorrent:latest

### Docker Compose

Docker compose is the recommended way to run this image. Copy the content of folder [examples/compose](examples/compose)
in `/var/rtorrent-rutorrent/` on your host for example. Edit the compose file with your preferences and run the
Docker compose is the recommended way to run this image. Copy the content of
folder [examples/compose](examples/compose) in `/var/rtorrent-rutorrent/` on
your host for example. Edit the compose file with your preferences and run the
following command:

```shell
Expand Down Expand Up @@ -208,21 +211,23 @@ docker run -d --name rtorrent_rutorrent \

### XMLRPC through nginx

rTorrent 0.9.7+ has a built-in daemon mode disabling the user interface, so you can only control it via XMLRPC. Nginx
will route XMLRPC requests to rtorrent through port `8000`. These requests can be secured with basic authentication
through the `/passwd/rpc.htpasswd` file in which you will need to add a username with his password. See below to
populate this file with a user / password.
rTorrent 0.9.7+ has a built-in daemon mode disabling the user interface, so you
can only control it via XMLRPC. Nginx will route XMLRPC requests to rtorrent
through port `8000`. These requests can be secured with basic authentication
through the `/passwd/rpc.htpasswd` file in which you will need to add a username
with his password. See below to populate this file with a user / password.

### WebDAV

WebDAV allows you to retrieve your completed torrent files in `/downloads/complete` on port `9000`. Like XMLRPC, these
requests can be secured with basic authentication through the `/passwd/webdav.htpasswd` file in which you will need to
add a username with his password. See below to populate this file with a user / password.
WebDAV allows you to retrieve your completed torrent files in `/downloads/complete`
on port `9000`. Like XMLRPC, these requests can be secured with basic authentication
through the `/passwd/webdav.htpasswd` file in which you will need to add a
username with his password. See below to populate this file with a user / password.

### Populate .htpasswd files

For ruTorrent basic auth, XMLRPC through nginx and WebDAV on completed downloads, you can populate `.htpasswd`
files with the following command:
For ruTorrent basic auth, XMLRPC through nginx and WebDAV on completed downloads,
you can populate `.htpasswd` files with the following command:

```
docker run --rm -it httpd:2.4-alpine htpasswd -Bbn <username> <password> >> $(pwd)/passwd/webdav.htpasswd
Expand All @@ -236,9 +241,10 @@ Htpasswd files used:

### Boostrap config `.rtlocal.rc`

When rTorrent is started the bootstrap config [/etc/rtorrent/.rtlocal.rc](rootfs/tpls/etc/rtorrent/.rtlocal.rc) is
imported. This configuration cannot be changed unless you rebuild the image or overwrite these elements in your
`.rtorrent.rc`. Here are the particular properties of this file:
When rTorrent is started the bootstrap config [/etc/rtorrent/.rtlocal.rc](rootfs/tpls/etc/rtorrent/.rtlocal.rc)
is imported. This configuration cannot be changed unless you rebuild the image
or overwrite these elements in your `.rtorrent.rc`. Here are the particular
properties of this file:

* `system.daemon.set = true`: Launcher rTorrent as a daemon
* A config layout for the rTorrent's instance you can use in your `.rtorrent.rc`:
Expand All @@ -265,19 +271,21 @@ imported. This configuration cannot be changed unless you rebuild the image or o

### Override or add a ruTorrent plugin/theme

You can add a plugin for ruTorrent in `/data/rutorrent/plugins/`. If you add a plugin that already exists in ruTorrent,
it will be removed from ruTorrent core plugins and yours will be used. And you can also add a theme in
`/data/rutorrent/themes/`. The same principle as for plugins will be used if you want to override one.
You can add a plugin for ruTorrent in `/data/rutorrent/plugins/`. If you add a
plugin that already exists in ruTorrent, it will be removed from ruTorrent core
plugins and yours will be used. And you can also add a theme in `/data/rutorrent/themes/`.
The same principle as for plugins will be used if you want to override one.

> ⚠️ Container has to be restarted to propagate changes
### Edit a ruTorrent plugin configuration

As you probably know, plugin configuration is not outsourced in ruTorrent. Loading the configuration of a plugin is
done via a `conf.php` file placed at the root of the plugin folder. To solve this issue with Docker, a special folder
has been created in `/data/rutorrent/plugins-conf` to allow you to configure plugins. For example to configure the
`diskspace` plugin, you will need to create the `/data/rutorrent/plugins-conf/diskspace.php` file with your
configuration:
As you probably know, plugin configuration is not outsourced in ruTorrent.
Loading the configuration of a plugin is done via a `conf.php` file placed at
the root of the plugin folder. To solve this issue with Docker, a special folder
has been created in `/data/rutorrent/plugins-conf` to allow you to configure
plugins. For example to configure the `diskspace` plugin, you will need to create
the `/data/rutorrent/plugins-conf/diskspace.php` file with your configuration:

```php
<?php
Expand All @@ -292,10 +300,32 @@ $partitionDirectory = null; // if null, then we will check rtorrent download dir
### Increase Docker timeout to allow rTorrent to shutdown gracefully

After issuing a shutdown command, Docker waits 10 seconds for the container to exit before it is killed. If you are a seeding many torrents, rTorrent may be unable to gracefully close within that time period. As a result, rTorrent is closed forcefully and the lockfile isn't removed. This stale lockfile will prevent rTorrent from restarting until the lockfile is removed manually.
After issuing a shutdown command, Docker waits 10 seconds for the container to
exit before it is killed. If you are a seeding many torrents, rTorrent may be
unable to gracefully close within that time period. As a result, rTorrent is
closed forcefully and the lockfile isn't removed. This stale lockfile will
prevent rTorrent from restarting until the lockfile is removed manually.

The timeout period can be extended by either adding the parameter `-t XX` to the docker command or `stop_grace_period: XXs` in docker-compose.yml, where `XX` is the number of seconds to wait for a graceful shutdown.
The timeout period can be extended by either adding the parameter `-t XX` to
the docker command or `stop_grace_period: XXs` in docker-compose.yml, where
`XX` is the number of seconds to wait for a graceful shutdown.

### WAN IP address

`WAN_IP` is the public IP address sent to the tracker. If you don't set `WAN_IP`,
then the container will automatically resolve your public IP address using the
command provided in `WAN_IP_CMD`.

This is useful to enforce the public IP address when you are behind a VPN where
an erroneous IP is sometimes reported. Here are some commands you can use if
the default one does not work:

* `dig +short myip.opendns.com @resolver1.opendns.com` (default)
* `curl -s ifconfig.me`
* `curl -s ident.me`

If `WAN_IP` is empty, and you set `WAN_IP_CMD` to `false` it will be ignored and
automatically determined by the tracker (recommended).

## Upgrade

Expand Down
2 changes: 2 additions & 0 deletions examples/compose/rtorrent-rutorrent.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ TZ=Europe/Paris
PUID=1000
PGID=1000

WAN_IP_CMD=false

AUTH_DELAY=0s
MEMORY_LIMIT=256M
UPLOAD_MAX_SIZE=16M
Expand Down
2 changes: 2 additions & 0 deletions examples/traefik/rtorrent-rutorrent.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ TZ=Europe/Paris
PUID=1000
PGID=1000

WAN_IP_CMD=false

AUTH_DELAY=0s
MEMORY_LIMIT=256M
UPLOAD_MAX_SIZE=16M
Expand Down
14 changes: 11 additions & 3 deletions rootfs/etc/cont-init.d/03-config.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/with-contenv sh
# shellcheck shell=sh

WAN_IP=${WAN_IP:-$(dig +short myip.opendns.com @resolver1.opendns.com)}
WAN_IP=${WAN_IP:-$(curl ifconfig.me)}
printf "%s" "$WAN_IP" > /var/run/s6/container_environment/WAN_IP
#WAN_IP=${WAN_IP:-10.0.0.1}
WAN_IP_CMD=${WAN_IP_CMD:-"dig +short myip.opendns.com @resolver1.opendns.com"}

TZ=${TZ:-UTC}
MEMORY_LIMIT=${MEMORY_LIMIT:-256M}
Expand Down Expand Up @@ -50,6 +49,15 @@ RUTORRENT_HEALTH_PORT=$((RUTORRENT_PORT + 1))
WEBDAV_PORT=${WEBDAV_PORT:-9000}
WEBDAV_HEALTH_PORT=$((WEBDAV_PORT + 1))

# WAN IP
if [ -z "$WAN_IP" ] && [ "$WAN_IP_CMD" != "false" ]; then
WAN_IP=$(eval "$WAN_IP_CMD")
fi
if [ -n "$WAN_IP" ]; then
echo "Public IP address enforced to ${WAN_IP}"
fi
printf "%s" "$WAN_IP" > /var/run/s6/container_environment/WAN_IP

# Timezone
echo "Setting timezone to ${TZ}..."
ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime
Expand Down
7 changes: 6 additions & 1 deletion rootfs/etc/cont-init.d/04-create-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ with-contenv
/bin/export HOME /data/rtorrent
/bin/export PWD /data/rtorrent
s6-setuidgid ${PUID}:${PGID}
rtorrent -D -o import=/etc/rtorrent/.rtlocal.rc -i ${WAN_IP}
EOL
if [ -z "${WAN_IP}" ]; then
echo "rtorrent -D -o import=/etc/rtorrent/.rtlocal.rc" >> /etc/services.d/rtorrent/run
else
echo "rtorrent -D -o import=/etc/rtorrent/.rtlocal.rc -i ${WAN_IP}" >> /etc/services.d/rtorrent/run
fi

chmod +x /etc/services.d/rtorrent/run

0 comments on commit c76617e

Please sign in to comment.