Library auto-updates on filesystem change?

Can anyone confirm that Plex under FreeBSD is (or should be) auto-updating libraries when PMS detects a filesystem change? I had seen mention a while back that kqueue wasn't properly being utilitized but I'm not sure if that's the case. I'm getting reports from my users that suggest it's not happening when they copy new content over and I have to manually refresh or they have to wait for the hourly scheduled refresh.

Correct. Wait for refresh or manual action. The feature works on my windows box but not freenas.

This is unfortunate and a bit of a pain. Others in the house have the ability to copy files to the server, but since they are not admins in PMS they can't manually refresh without my assistance and I'm not always home. Can anyone on the Plex team chime in on this, why this is the case and any hope for remedy?

If this matters to you, please "Like" the first post in this "Feature & Bug Voting" thread:

https://forums.plex.tv/topic/135934-properly-implement-kqueue-to-allow-pms-to-auto-update-library-on-filesystem-change-freebsd/

Thanks!

hmm.. Maybe you could use something with fswatch and a call to "Plex Media Scanner" to start a scan...

Something like...

# then in a tmux instance or something...
while 1; do
  src/fswatch --print0 --one-event --recursive /tmp/ | while read -d '' event; do
     sleep 300 # sleep a few minutes so the file is done copying before starting scan?
     /usr/local/share/plexmediaserver-plexpass/Plex\ Media\ Scanner -s 
  done
done

Haven't tried it myself, but it seems like a plausible stopgap solution. You may need to call the scanner in a subsequent shell script, to set the appropriate LD_LIBRARY_PATH.

EDIT: Slightly better scripted proposal, without needing the script to deal with lock to avoid multiple invocations.

EDIT2: removed incorrect package install

hmm.. Maybe you could use something with fswatch and a call to "Plex Media Scanner" to start a scan...

Something like...

$ pkg install fswatch

then in a tmux instance or something…

while 1; do
src/fswatch --print0 --one-event --recursive /tmp/ | while read -d ‘’ event; do
sleep 300 # sleep a few minutes so the file is done copying before starting scan?
/usr/local/share/plexmediaserver-plexpass/Plex\ Media\ Scanner -s
done
done

Haven't tried it myself, but it seems like a plausible stopgap solution. You may need to call the scanner in a subsequent shell script, to set the appropriate LD_LIBRARY_PATH.

EDIT: Slightly better scripted proposal, without needing the script to deal with lock to avoid multiple invocations.

Interesting idea!  I've been using a similar approach with wait_on.  I think I'm going to modify my scripts to use fswatch instead.

Oh, one thing.  'pkg install fswatch' doesn't install the fswatch that you want.  The fswatch that pkg installs is some file system checksum checker.  It must be a different program with the same name.  fswatch will have to be installed from source from the link you posted.

ah. nice catch. 

I had a chance to test fswatch on my plex install which is on freenas 9.3 in a regular jail.  Getting fswatch to compile was a bit of an issue.  Turns out clang35 is needed.  You also need to compile libc++ and libxxrt with c++11 support.  Supposedly on freebsd 10 or higher there are no issues compiling fswatch.

Anyway, fswatch is working well.  I'm running fswatch with the daemon command which is called from a custom rc script that I made.  One problem though; '/usr/local/share/plexmediaserver-plexpass/Plex\ Media\ Scanner -s' does not work properly. New media is added to my library but no metadata/poster is downloaded.  Instead I have to use 'wget --spider --quiet http://localhost:32400/library/sections/all/refresh' to refresh things properly.

Here are my scripts:

/usr/local/etc/rc.d/scanmedia

#!/bin/sh
#
# PROVIDE: scanmedia
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable scanmedia :
#
# scanmedia_enable (bool):             Set it to "YES" to enable scanmedia
#                                      Default is "NO".
 
. /etc/rc.subr
 
name="scanmedia"
rcvar=`set_rcvar`
load_rc_config $name
 
: ${scanmedia_enable:=NO}
: ${scanmedia_user="plex"}
 
start_precmd="${name}_pre"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
pidfile="/var/run/${name}/${name}.pid"
 
scanmedia_pre() {
if [ ! -d ${pidfile%/*} ]; then
install -d -o ${scanmedia_user} ${pidfile%/*};
fi 
}
 
scanmedia_start() { 
if [ -f "${pidfile}" ]; then
echo "${name} is already running with pid: $(cat ${pidfile})";
else
echo "starting $name."
/usr/sbin/daemon -f -p ${pidfile} -u ${scanmedia_user} /usr/local/bin/scanmedia
fi
}
 
scanmedia_stop() {
    if [ -f "${pidfile}" ]; then
            main_pid=$(cat ${pidfile});
            child_pids=$(pgrep -P ${main_pid});
            child_pids="${child_pids} $(pgrep -P ${child_pids})"
            all_pids="${main_pid} ${child_pids}"
echo "Stopping $name."
            kill ${sig_stop} ${all_pids};
            wait_for_pids ${all_pids};
    else
            echo "${name} is not running.";
            exit 1;
    fi
}

 

/usr/local/bin/scanmedia

#!/usr/local/bin/bash
 
PATH="$PATH:/usr/local/bin"
 
# Variables used in this script...
 
# TriggeredDelay = The amount of time in seconds to delay rescanning from the point of a
# change being detected.  The default is 300 seconds (5 minutes).  Change to your liking
# and think of this as how long it takes you to write a large file (movie) to your NAS.
TriggeredDelay=300
 
# MediaLocation = The location your want to scan for your media.  The default is "/media".
MediaLocation="/media"
 
####  Required for Plex Media Scanner
export plexmediaserver_support_path="/usr/local/plexdata"
export SUPPORT_PATH="${plexmediaserver_support_path}"
export HOME="${plexmediaserver_support_path}/Plex Media Server"
export PYTHONHOME="/usr/local/share/plexmediaserver/Resources/Python"
export SCRIPTPATH="/usr/local/share/plexmediaserver"
export LD_LIBRARY_PATH="${SCRIPTPATH}"
export PLEX_MEDIA_SERVER_HOME="${SCRIPTPATH}"
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=${plexmediaserver_support_path}
export PLEX_MEDIA_SERVER_PIDFILE=${pidfile}
export PATH="${SCRIPTPATH}/Resources/Python/bin:${PATH}"
export LC_ALL="C"
export LANG="C"
ulimit -s 3000
####
 
while :; do
  fswatch --print0 --one-event --recursive $MediaLocation | while read -d '' event; do
    sleep $TriggeredDelay
    #'/usr/local/share/plexmediaserver/Plex Media Scanner' -s
    wget --spider --quiet http://localhost:32400/library/sections/all/refresh
  done
done

 

Add to /etc/rc.conf

scanmedia_enable="YES"

 

Oh, you also require bash installed.  Install with: 'pkg install bash'

great job ironing out the details kjp001!

How is this on system resources?

load_rc_config $name
run_rc_command “$1”

was missing from the last 2 line of the rc.d/scanmedia file for me, that made the rc.d script not trigger.

Is it working on the last PMS 1.15.5 / FreeBSD? I set 2 options “Scan my library automatically” and “Run a partial scan when changes are detected”, but nothing changes.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.