LightDestory / PlexNFSWatchdog

A utility to trigger Plex partial-scans on NFS configurations, on which inotify is not supported
GNU General Public License v3.0
3 stars 0 forks source link

Watchdog Daemon not working #3

Closed m4chine closed 1 week ago

m4chine commented 3 weeks ago

Description

I cannot get the --daemon to trigger a partial scan. I tried both as a regular user and root but the daemon is not picking up changes.

When I run the manual scan, it picks up the the changes and runs a partial scan.

Reproduction

Daemon does not work: plex-nfs-watchdog --daemon --paths /mnt/media/movies/ /mnt/media/tv --interval 150 --listeners move modify create delete &

Manual scan works: plex-nfs-watchdog --scan --paths /mnt/media/movies/ /mnt/media/tv --interval 150 --listeners move modify create delete

Environment

Arch Linux 6.10.5-arch1-1 I did use pipx to install plex-nfs-watchdog vs. pip

Am I doing something wrong? Thanks in advance.

LightDestory commented 3 weeks ago

Any error?

Run the tool without the background operator '&' to see what it does print.

m4chine commented 3 weeks ago

No error.

$ plex-nfs-watchdog --daemon --paths /mnt/media/movies/ /mnt/media/tv --interval 150 --listeners move modify create delete INFO: Found Plex configuration from cache: /home/[user]/.local/share/plex_nfs_watchdog_cache/plex_config.json INFO: Connected to Plex server INFO: Plex version: 1.40.5.8854-f36c552fd INFO: Found 3 Plex sections: {'movies': ('Movies', '/mnt/media/movies'), 'music': ('Music', '/mnt/media/music'), 'tv': ('TV Shows', '/mnt/media/tv')} INFO: Scheduling watcher for /mnt/media/movies INFO: Scheduling watcher for /mnt/media/tv INFO: Registering inotify watcher... INFO: Ready to operate...

Are there any logs anywhere to inspect besides console out?

m4chine commented 3 weeks ago

$ mount -l ... remote_addr:/volume1/downloads/media on /mnt/media type nfs4 (rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=local_addr,local_lock=none,addr=remote_addr) ...

LightDestory commented 3 weeks ago

No error.

$ plex-nfs-watchdog --daemon --paths /mnt/media/movies/ /mnt/media/tv --interval 150 --listeners move modify create delete INFO: Found Plex configuration from cache: /home/[user]/.local/share/plex_nfs_watchdog_cache/plex_config.json INFO: Connected to Plex server INFO: Plex version: 1.40.5.8854-f36c552fd INFO: Found 3 Plex sections: {'movies': ('Movies', '/mnt/media/movies'), 'music': ('Music', '/mnt/media/music'), 'tv': ('TV Shows', '/mnt/media/tv')} INFO: Scheduling watcher for /mnt/media/movies INFO: Scheduling watcher for /mnt/media/tv INFO: Registering inotify watcher... INFO: Ready to operate...

Are there any logs anywhere to inspect besides console out?

From this log I can see that the watcher successfully started.

Now, try to insert some content on such libraries. You must use the Plex recommended directory-structure of a folder per show

m4chine commented 3 weeks ago

So I wasn't questioning whether or not the process started successfully and was in fact running.

My problem is when running in plex-nfs-watchdog --daemon, it is not picking up the media additions when the process should be monitoring the two folders "-paths /mnt/media/movies/ /mnt/media/tv" for changes. I add media to mnt/media/movies or mnt/media/tv, the addition is not reflected in Plex. But I then run plex-nfs-watchdog --scan and it picks up the media that should have been picked up from the plex-nfs-watchdog --daemon process.

From the console output, "scheduling watcher "or "registering inotify watcher" is not working properly.

  1. Add movie1 to /mnt/media/movies
  2. Run plex-nfs-watchdog --daemon ...
  3. Plex does not show movie1
  4. run plex-nfs-watchdog --scan
  5. Plex does show movie1

Am I able to properly convey my problem?

LightDestory commented 3 weeks ago

So I wasn't questioning whether or not the process started successfully and was in fact running.

My problem is when running in plex-nfs-watchdog --daemon, it is not picking up the media additions when the process should be monitoring the two folders "-paths /mnt/media/movies/ /mnt/media/tv" for changes. I add media to mnt/media/movies or mnt/media/tv, the addition is not reflected in Plex. But I then run plex-nfs-watchdog --scan and it picks up the media that should have been picked up from the plex-nfs-watchdog --daemon process.

From the console output, "scheduling watcher "or "registering inotify watcher" is not working properly.

  1. Add movie1 to /mnt/media/movies
  2. Run plex-nfs-watchdog --daemon ...
  3. Plex does not show movie1
  4. run plex-nfs-watchdog --scan
  5. Plex does show movie1

Am I able to properly convey my problem?

A daemon is a background service... you are doing on the wrong order:

  1. First start the daemon and let it run on the background;
  2. Add a movie to your library;
  3. The watcher detects a change and it will provide a path to Plex to perform a partial scan;
m4chine commented 2 weeks ago

You're not understanding what I'm saying. I understand what a daemon is.

I do not want to run plex-nfs-watchdog --scan manually. I am simply pointing out it works with my configuration. My original post points this out.

I want to run plex-nfs-watchdog --daemon. It is not working. The watcher is not detecting changes.

I did however mix up the sequence of events in my last post, the following is accurate.

  1. Run plex-nfs-watchdog --daemon ...
  2. Add movie1 to /mnt/media/movies --- I wait 2 minutes to pass for the sleep command in your code. HERE I SHOULD SEE Plex library updated to add movie1, BUT the watcher does NOT pick up movie1 and it is not seen in Plex library. --
  3. run plex-nfs-watchdog --scan -- Plex library NOW SEES movie1. Same configuration, only difference in the command is --daemon vs --scan --

plex-nfs-watchdog --daemon DOES NOT WORK, plex-nfs-watchdog --scan DOES WORK.

Does this make better sense?

LightDestory commented 2 weeks ago

Do you see the log about queueing the file? https://github.com/LightDestory/PlexNFSWatchdog/blob/master/src/plex_nfs_watchdog/modules/plex/plex_agent.py#L240

The parse_event function is called by https://github.com/LightDestory/PlexNFSWatchdog/blob/master/src/plex_nfs_watchdog/modules/watchdog/plex_watchdog_event.py that is just an implementation of FileSystemEventHandler by the watchdog library.

The IO change detection is not something that I have implementend myself, I am using the mainstream library for that.

m4chine commented 2 weeks ago

I did some further testing.

nfsserver - running the NFS server plexserver - running plex, plex-nfs-watchdog and mounted the remote NFS share on nfsserver

When creating a folder via plexserver on the mounted NFS share, the folder is queued and works as intended.

When creating a folder via nfsserver on its local filesystem which is shared via NFS, plex-nfs-watchdog on the plexserver does not pick up the folder creation and therefor not queued and does not work as intended.

Should plexserver pickup a folder creation that was initiated via nfsserver?

LightDestory commented 2 weeks ago

Assuming we have 2 servers:

When an operation is performed on a file inside the StorageServer, StreamServer does not notice it because NFS does not provide for inotify.

That is why I developed this utility: it must be run inside the server that performs operations on the data.

So the watchdog must be started inside the StorageServer and must be able to communicate via HTTP with the StreamServer

If you want to be able to track changes on both your server you should run an instance of the watchdog inside every datastore and point all of them to the same PlexServer

m4chine commented 1 week ago

Thank you! I moved the script to nfsserver/StorageServer and eventually got it working.

It took some python investigation, as the current plex-nfs-watchdog code base looks to require some newer python coding features.

For others awareness, I first tried python-3.8 and python-3.9, both producing different errors.

python-3.8 Error: TypeError: 'type' object is not subscriptable python-3.9 Error: TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

And finally got the code working on python-3.11.

Thanks again @LightDestory for your support.