Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain Transmission settings.json values can only be set by ENV var #2827

Open
7 of 8 tasks
phipolis opened this issue Apr 21, 2024 · 6 comments
Open
7 of 8 tasks

Certain Transmission settings.json values can only be set by ENV var #2827

phipolis opened this issue Apr 21, 2024 · 6 comments

Comments

@phipolis
Copy link

Is there a pinned issue for this?

  • I have read the pinned issues and could not find my issue

Is there an existing or similar issue/discussion for this?

  • I have searched the existing issues
  • I have searched the existing discussions

Is there any comment in the documentation for this?

  • I have read the documentation, especially the FAQ and Troubleshooting parts

Is this related to a provider?

  • I have checked the provider repo for issues
  • My issue is NOT related to a provider

Are you using the latest release?

  • I am using the latest release

Have you tried using the dev branch latest?

  • I have tried using dev branch

Docker run config used

services:
 transmission:
  image: haugene/transmission-openvpn:latest
  cap_add:
    - NET_ADMIN
  devices:
    - /dev/net/tun
  dns:
    - 1.1.1.1
  sysctls:
    - net.ipv6.conf.all.disable_ipv6=0
  restart: always
  ports:
    - "127.0.0.1:9092:9091"
  volumes:
    - /etc/localtime:/etc/localtime:ro 
    - /path/transmission-openvpn:/config
    - /path/Torrents:/data
    ## Previous config:
    # - /Path/Torrents:/data/completed 
    # - /Path/Torrents/incomplete:/data/incomplete 
    # - /Path/Torrents/transmission-home:/config/transmission-home/
  logging:
    options:
      max-size: 10m
  environment:
    - TZ=[redacted]
    - OPENVPN_PROVIDER=[redacted] 
    - OPENVPN_USERNAME=[redacted]
    - OPENVPN_PASSWORD=m
    - CREATE_TUN_DEVICE=false
    - OPENVPN_CONFIG=[redacted]
    - OPENVPN_OPTS=--inactive 3600 --ping 10 --ping-exit 60
    - LOCAL_NETWORK=192.168.1.0/24
    - WEBPROXY_ENABLED=false
    - PGID=100
    - PUID=1026

Current Behavior

I had gotten my setup working in the pre-4.2 days by bind-mounting onto the paths /data/completed , /data/incomplete, and /config/transmission-home. Urgent warnings in the logs prompted me to change my mounts and benefit from the new persistent config.
When I did so, some options in the config file inexplicably got overwritten by ENV vars I hadn't set (by the project Dockerfile and updateSettings.py).

Expected Behavior

I expected ALL the transmission values to be usable from settings.json. When I realized there were exceptions that must go through ENV, expected they would have been listed in the docs. That the file described as persistent and safe to edit was getting overwritten with hidden defaults was not expected.

(As an aside, I also think that reading docker secrets and writing them out to files on a bind-mounted volume is pretty surprising behavior and not what most people think is going to happen when they use them. One might go as far as saying it defeats secrets' purpose.)

How have you tried to solve the problem?

Much reading of source and triple checking my config until I understood what was happening

Log output

Starting container with revision: 07f5a2b
TRANSMISSION_HOME is currently set to: /config/transmission-home
[...]
Updating Transmission settings.json with values from env variables
Attempting to use existing settings.json for Transmission
Successfully used existing settings.json /config/transmission-home/settings.json
[...]
Overriding download-dir because TRANSMISSION_DOWNLOAD_DIR is set to /data/completed
Overriding incomplete-dir because TRANSMISSION_INCOMPLETE_DIR is set to /data/incomplete
Overriding rpc-password because TRANSMISSION_RPC_PASSWORD is set to [REDACTED]
Overriding rpc-port because TRANSMISSION_RPC_PORT is set to 9091
Overriding rpc-username because TRANSMISSION_RPC_USERNAME is set to
Overriding watch-dir because TRANSMISSION_WATCH_DIR is set to /data/watch
[...]
Transmission startup script complete.

HW/SW Environment

- OS: DSM7
- Docker: 20.10.23

Anything else?

The Transmission configuration options docs section says
In previous versions of this container the settings were not persistent but were generated from environment variables on container startup. [...] Settings are now persisted in the /config/transmission-home folder in the container and as long as you mount /config you should be able to configure Transmission using the UI as you normally would.

The docs imply that settings ARE persistent, configuring transmission via ENV vars is not necessary, and that I could do everything in settings.json as long as I use the UI or make edits while the container is stopped. So when basic options like download-dir and incomplete-dir were getting overwritten, I was very confused.

The logs did explain they were being overridden by ENV, but my compose file didn't have any TRANSMISSION_* vars set! I was pulling my hair out until I realized the container came with ENV vars baked in that always take precedence unless I shadow them with my own values.

@skywayskase
Copy link

Yep, I'm experiencing this same issue as well. Once I restart the container, any settings I set in the previous instance, or manually set in the config file while the container was off, are overwritten unless I specify the settings as env variables when I start the container. I opened a discussion about this a little over a year ago but the issue was never resolved (I think I closed the discussion and just set my env variables and let it be).

@pkishino
Copy link
Collaborator

So, just to clarify here, you are seeing that manually setting certain options (only those that we have as necessary defaults in our setup or also others?) get overwritten in settings.json by these defaults if you don’t manually set them as env variables?
I think we need to do a deep dive on this and first get a complete list of which variables.
I know that we set a number of env variables when the container starts but none of these are UI settings afaik.
these settings are there to ensure a usable container is started first time on

@skywayskase
Copy link

So, just to clarify here, you are seeing that manually setting certain options (only those that we have as necessary defaults in our setup or also others?) get overwritten in settings.json by these defaults if you don’t manually set them as env variables? I think we need to do a deep dive on this and first get a complete list of which variables. I know that we set a number of env variables when the container starts but none of these are UI settings afaik. these settings are there to ensure a usable container is started first time on

Because several ENV variables are set in the dockerfile, anytime the container is (re)created, those values will overwrite their corresponding settings in the settings.json file, unless different ENV variables are specified at runtime. I rectreate my container all the time, particularly when updating the image.

This was especially an issue because my Transmission RPC credentials kept getting reset to the default (blank) values until I manually specified them as ENV variables in docker run. And because it was behind a proxy and open to the world, that meant anyone who knew the URL had full access and could download whatever they wanted to my server until I figured out the issue and "fixed" it.

@phipolis
Copy link
Author

phipolis commented May 1, 2024

To illustrate @skywayskase's excellent summary:

The Dockerfile sets these ENV TRANSMISSION_* with default values:

TRANSMISSION_RPC_PORT=9091 \
TRANSMISSION_RPC_USERNAME= \
TRANSMISSION_RPC_PASSWORD= \
TRANSMISSION_DOWNLOAD_DIR=/data/completed \
TRANSMISSION_INCOMPLETE_DIR=/data/incomplete \
TRANSMISSION_WATCH_DIR=/data/watch \

updateSettings.py will always overwrite settings.json with values found in ENV vars:

# For each setting, check if an environment variable is set to override it
for setting in settings_dict:
setting_is_sensitive = setting == "rpc-password"
setting_env_name = setting_as_env(setting)
if setting_env_name in os.environ:
env_value = os.environ.get(setting_env_name)
env_log_value = "[REDACTED]" if setting_is_sensitive else env_value
# Coerce env var values to the expected type in settings.json
if type(settings_dict[setting]) == bool:
env_value = env_value.lower() == 'true'
else:
setting_type = type(settings_dict[setting])
try:
env_value = setting_type(env_value)
except ValueError:
print(
'Could not coerce {setting_env_name} value {env_log_value} to expected type {setting_type}'.format(
setting_env_name=setting_env_name,
env_log_value=env_log_value,
setting_type=setting_type,
),
)
raise
print(
'Overriding {setting} because {env_name} is set to {value}'.format(
setting=setting,
env_name=setting_env_name,
value=env_log_value,
),
)
settings_dict[setting] = env_value
# Dump resulting settings to file
with open(transmission_settings, 'w') as fp:
json.dump(settings_dict, fp)

So the only way to change those settings is to override the environment variables when starting the container.

@lodart
Copy link

lodart commented Jun 28, 2024

Same issue here. I've been banging my head against the wall for hours, now I understand 😌

@SESNut
Copy link

SESNut commented Oct 26, 2024

my downloads kept going into /mnt/hgfs/transmission/torrents in the container no matter what i set as the data dir or download dir. The settings.json listed the download path that i set but they would still go into the container path. The only way i could make completed torrents go into the folder i wanted was to specifically set a volume for /mnt/hgfs/transmission/torrents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants