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

Not looking for files in subdirectories dynamically #3986

Open
BullHacks3 opened this issue Oct 8, 2018 · 8 comments
Open

Not looking for files in subdirectories dynamically #3986

BullHacks3 opened this issue Oct 8, 2018 · 8 comments
Labels
area/provider/file contributor/wanted Participation from an external contributor is highly requested kind/bug/confirmed a confirmed bug (reproducible).

Comments

@BullHacks3
Copy link

Issue

Traefik file handlers not looking for the files in the subdirectories
https://docs.traefik.io/configuration/backends/file/#multiple-separated-files
In documentation ,it is clearly mentioned ,that file handlers have capability to look into the subdirectories for the files dynamically

How to reproduce the issue

Step 1:- Contents of the main.toml file

defaultEntryPoints = ["http"]
[entryPoints]
  [entryPoints.http]
  address = ":80"
  [api]
 entrypoint="dashboard"
  dashboard= true
  debug=true

[file]
  directory= "/home/traefik/hostRules/"
  watch=true

Step 2:- Now I am dynamically creating the subdirectories inside the mounted directory

try

For example the dummy configuration of one of the traefik file is:-

[file]
[frontends]
    [frontends.front_end_abc]
         backend="backend3"
        passHostHeader = true
    [frontends.front_end_abc.routes.first]
         rule="Host: testingpurpose.com"
   [backends]
    [backends.backend3]
         [backends.backend3.servers.first]
           url = "http://192.168.1.2:39832"

But the configurations are not loaded dynamically until ,I restart the docker image
Command used to up the docker container

docker run -d -v /home/traefik:/home/traefik -p 80:80  -p 443:443 -p 172.31.30.68:8080:8080 testing-traefik /usr/bin/traefik -c /home/traefik/main.toml

What did you expect to see?

I expected that the configurations inside the subdirectories should be loaded dynamically without restarting the docker image

What did you see instead?

I have to restart the docker image ,in order to load the configurations inside the subdirectories that are creating dynamically.

Output of traefik version: (What version of Traefik are you using?)

Used the latest traefik image ,for building own docker image on the top of centos
@ldez ldez added kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed. area/provider/file priority/P2 need to be fixed in the future and removed status/0-needs-triage labels Oct 8, 2018
@nmengin
Copy link
Contributor

nmengin commented Oct 9, 2018

Hello @BullHacks3 ,

Many thanks for interest in the project.

I guess the problem comes from the watcher we use which is not recursive.
Indeed, Træfik can load file from subbdirectories but can not listen to events from these subdirectories.

As a workaround, by waiting for the fix, you can touch a file in the root directory when a modification is done in a subdirectory to load all the configuration (or make a modification in an existing file).
It is not perfect bu more dynamic than restarting Træfik.

@nmengin nmengin added priority/P1 need to be fixed in next release kind/bug/confirmed a confirmed bug (reproducible). and removed kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed. priority/P2 need to be fixed in the future labels Oct 9, 2018
@GuyFromMars365
Copy link

I'm guessing this isn't going to get fixed, since last update was 1.5 years ago? :(

@jspdown
Copy link
Contributor

jspdown commented Jan 12, 2021

The issue is due to fsnotify/fsnotify not capable of watching file recursively. To provide a cross platform solution, fsnotify relies on adapters (inotify, ReadDirectoryChangesW, kqueue) but recursive file watching is not supported everywhere. There is some work in progress (fsnotify/fsnotify#18, fsnotify/fsnotify#114, fsnotify/fsnotify#12) to bring support but we are not yet there.

An alternative would be to implement a user-space solution based on filepath.Walk. It wouldn't be great in term of performance an addressing edge cases (as there are several) might lead to a complex implementation.

@rassie

This comment has been minimized.

@rizlas
Copy link

rizlas commented Nov 26, 2021

Same in Traefik v2.5

@elgarfo
Copy link

elgarfo commented Oct 14, 2022

same for traefik v2.9.1

based on @nmengins suggestion we're using an alpine container with inotify-tools to watch for file changes recursively and touch an empty file in traefiks dynamic conf root:

docker run  --rm -it \
  -v $PWD/traefik.d/:/watchme:ro \
  -v $PWD/traefik.d/.please_reread_files_traefik:/touchme \
  alpine \
  sh -c 'apk update && apk add inotify-tools && while true; do inotifywait -e modify,create,delete,attrib -r /watchme && touch /touchme; done'

@nmengin
Copy link
Contributor

nmengin commented Nov 28, 2023

Hello,

I link this issue to the PR #9993.
Even if sending a signal doesn't solve the issue, IMO it's a good enough workaround.

If any contributor finds a better solution, we would love community support to address it.
Let us know, and we will work with you to make sure you have all the information needed so that it can be merged.

@nmengin nmengin added contributor/wanted Participation from an external contributor is highly requested and removed priority/P1 need to be fixed in next release labels Nov 28, 2023
@centja1
Copy link

centja1 commented May 8, 2024

Not sure if responding on a 6 month old thread is the right place, but is there a reason why there is code in the File provider to specifically exclude adding a watcher for sub directories?

I understand that you cannot recursively monitor a sub-directory that is created after traefik has started, but adding a file to a sub-directory that existed at startup also does not work, and it would appear that this is intentional.

I forked the repo, commented out those lines and built an image and can confirm that creating a new file within a sub-directory that existed at start does automatically load the config from that file.

Curious as to why lines 69-72 exist

Screenshot from 2024-05-07 22-29-17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/provider/file contributor/wanted Participation from an external contributor is highly requested kind/bug/confirmed a confirmed bug (reproducible).
Projects
None yet
Development

No branches or pull requests