Media scanner cli is crashing [fixed] - needed env variable set

Server Version#: 1.19.4.2935
Player Version#:n/a

Been a while since I tried this so I don’t know if it’s been broken, but I tried to invoke the media scanner from the cli and it crashes consistently:

$ export LD_LIBRARY_PATH=/usr/local/share/plexmediaserver
$ /usr/local/share/plexmediaserver/Plex\ Media\ Scanner --list
Abort trap (core dumped)

No log entries happen.
I use https://www.freshports.org/multimedia/plexmediaserver/ as the source of my package.

FWIW scans initiated from the web interface are working fine:

$ tail -f /usr/local/plexdata/Plex\ Media\ Server/Logs/Plex\ Media\ Scanner.log
Jun 30, 2020 13:32:05.038 [0x80b7f4300] DEBUG - HTTP 200 response from GET http://127.0.0.1:32400/:/metadata/updateProgressMessage?message=Scanning%20CCNP%2FCCNP%20Security%20FIREWALL%20v2%2E0%20642-618
Jun 30, 2020 13:32:05.038 [0x8049ad000] DEBUG - HTTP 200 response from PUT http://127.0.0.1:32400/activities/ecb851a2-24a4-4467-bc0f-8deaf012fbbb?percentComplete=%2B0%2E532258093&subtitle=CCNP%20Security%20FIREWALL%20v2%2E0%20642-618
Jun 30, 2020 13:32:05.038 [0x8049ad000] DEBUG - HTTP requesting PUT http://127.0.0.1:32400/activities/ecb851a2-24a4-4467-bc0f-8deaf012fbbb?percentComplete=99.000000
Jun 30, 2020 13:32:05.039 [0x8049ad000] DEBUG - HTTP 200 response from PUT http://127.0.0.1:32400/activities/ecb851a2-24a4-4467-bc0f-8deaf012fbbb?percentComplete=99.000000
Jun 30, 2020 13:32:05.039 [0x8049ad000] DEBUG - Removing 0 media items that were left.
Jun 30, 2020 13:32:05.039 [0x8049ad000] DEBUG - Removing 0 directories that were left.
Jun 30, 2020 13:32:05.066 [0x8049ad000] DEBUG - HTTP requesting PUT http://127.0.0.1:32400/activities/ecb851a2-24a4-4467-bc0f-8deaf012fbbb?percentComplete=100
Jun 30, 2020 13:32:05.066 [0x8049ad000] DEBUG - HTTP 200 response from PUT http://127.0.0.1:32400/activities/ecb851a2-24a4-4467-bc0f-8deaf012fbbb?percentComplete=100
Jun 30, 2020 13:32:05.066 [0x8049ad000] DEBUG - Refreshing section 12 of type: 2
Jun 30, 2020 13:32:05.078 [0x80b7f3400] DEBUG - Refreshing 0 IDs.

A link to the syscalls: https://paste.ee/p/GQDB4

export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/usr/local/plexdata

Thanks. Interesting. Better, but It still crashes:

$ export LD_LIBRARY_PATH=/usr/local/share/plexmediaserver
$ export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/usr/local/plexdata
$ /usr/local/share/plexmediaserver/Plex\ Media\ Scanner --list
Abort trap

syscall diff https://paste.ee/p/RBsPR

nm, it’s good. Not sure what I messed up above, but I set the variables again and it worked. Thanks a lot for the info.

Hrmph. It seems like those are the two that I need, and it looks like they’re the right paths for your system, too.

You’re running as ~plex?

What’s env show?

Oh yay!

look at the envs in the rc.d script, that should help, and also be sure to run as “plex”.

There’s a start.sh script included in the install dir, you could edit it to run the scanner i.e.

Agreed about /usr/local/etc/rc.d/plexmediaserver, though you have to figure out which parts Plex needs and which parts are for the FreeBSD RC system.

Note that start.sh doesn’t actually set PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR.

My favorite for this stuff (on FreeBSD) is

$ procstat -e `pid`

All exports should be applicable but some are not needed to run things, jut optional (as i.e the if for checking if you’re on FreeNAS)

This is likely all you need:

export plexmediaserver_support_path="/usr/local/plexdata/"
export SUPPORT_PATH="${plexmediaserver_support_path}"
export HOME="${plexmediaserver_support_path}/Plex Media Server"
SCRIPT=$(readlink -f $0)
SCRIPTPATH=$(dirname ${SCRIPT})
export LD_LIBRARY_PATH="${SCRIPTPATH}/lib"
export PLEX_MEDIA_SERVER_HOME="${SCRIPTPATH}"
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"
export PYTHONHOME="${SCRIPTPATH}/Resources/Python"
export PATH="${SCRIPTPATH}/Resources/Python/bin:${PATH}"
ulimit -s 3000
./Plex\ Media\ Server

Do note that on FreeNAS specifically that first one might be “/” or you need to adapt to -plexpass in any case all the others should be the same (well PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS could also be changed I suppose.

This also assumes its called inside the install dir.

start.sh doesn’t set PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR.

If you change start.sh to launch Plex Media Scanner, that environment variable needs to be set and exported too.

This is a modified start.sh see the top:

export SUPPORT_PATH="${plexmediaserver_support_path}"
export HOME="${plexmediaserver_support_path}/Plex Media Server"

:man_shrugging:

If I don’t set PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR then Plex Media Scanner doesn’t work for me. SUPPORT_PATH isn’t enough.

$ env
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/tmp/bin
PWD=/usr/local/share/plexmediaserver
TERM=xterm-256color
USER=plex
HOME=/tmp
SHELL=/bin/sh
$ ./Plex\ Media\ Scanner -l
Abort trap
$ export LD_LIBRARY_PATH=/usr/local/share/plexmediaserver
$ export SUPPORT_PATH=/usr/local/plexdata
$ ./Plex\ Media\ Scanner -l
Abort trap
$ export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${SUPPORT_PATH}"
$ ./Plex\ Media\ Scanner -l
  2: Movies
 22: Music
  1: TV
$

Its actually HOME that’s doing the same not the other, sorry I should have clarified!

You can even set both but PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR should default to “HOME”; also “HOME” might be needed elsewhere but probably on PMS and not the scanner (unsure) either way for you’re use case if that one works and you don’t need HOME than I suppose that’s fine!

I just wanted to leave here a fill start.sh that should work to start any of the binaries (just like the rc.d script does)

It doesn’t work for me if HOME is set to /usr/local/plexdata//Plex Media Server or /usr/local/plexdata.

I have to set PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR to /usr/local/plexdata for it to work.

[plex@plex /usr/local/share/plexmediaserver]$ export plexmediaserver_support_path="/usr/local/plexdata/"
[plex@plex /usr/local/share/plexmediaserver]$ export SUPPORT_PATH="${plexmediaserver_support_path}"
[plex@plex /usr/local/share/plexmediaserver]$ export HOME="${plexmediaserver_support_path}/Plex Media Server"
[plex@plex /usr/local/share/plexmediaserver]$ SCRIPTPATH=/usr/local/share/plexmediaserver 
[plex@plex /usr/local/share/plexmediaserver]$ export LD_LIBRARY_PATH="${SCRIPTPATH}/lib"
[plex@plex /usr/local/share/plexmediaserver]$ export PLEX_MEDIA_SERVER_HOME="${SCRIPTPATH}"
[plex@plex /usr/local/share/plexmediaserver]$ export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
[plex@plex /usr/local/share/plexmediaserver]$ export LC_ALL="en_US.UTF-8"
[plex@plex /usr/local/share/plexmediaserver]$ export LANG="en_US.UTF-8"
[plex@plex /usr/local/share/plexmediaserver]$ export PYTHONHOME="${SCRIPTPATH}/Resources/Python"
[plex@plex /usr/local/share/plexmediaserver]$ export PATH="${SCRIPTPATH}/Resources/Python/bin:${PATH}"
[plex@plex /usr/local/share/plexmediaserver]$ ulimit -s 3000
[plex@plex /usr/local/share/plexmediaserver]$ ./Plex\ Media\ Scanner -l
[plex@plex /usr/local/share/plexmediaserver]$ echo $HOME
/usr/local/plexdata//Plex Media Server
[plex@plex /usr/local/share/plexmediaserver]$ export HOME="${plexmediaserver_support_path}"
[plex@plex /usr/local/share/plexmediaserver]$ ./Plex\ Media\ Scanner -l
Abort trap
[plex@plex /usr/local/share/plexmediaserver]$ echo $HOME
/usr/local/plexdata/
[plex@plex /usr/local/share/plexmediaserver]$ ./Plex\ Media\ Scanner -l
Abort trap
[plex@plex /usr/local/share/plexmediaserver]$ export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${SUPPORT_PATH}"
[plex@plex /usr/local/share/plexmediaserver]$ ./Plex\ Media\ Scanner -l
  2: Movies
 22: Music
  1: TV

I just noticed this. It behaves differently when HOME is set to different values. But it doesn’t WORK until PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR is set correctly.

From your script - no error, no output, doesn’t work, just returns to prompt:

[plex@plex /usr/local/share/plexmediaserver]$ echo $HOME
/usr/local/plexdata//Plex Media Server
[plex@plex /usr/local/share/plexmediaserver]$

Changed HOME, now an error message:

[plex@plex /usr/local/share/plexmediaserver]$ echo $HOME
/usr/local/plexdata/
[plex@plex /usr/local/share/plexmediaserver]$ ./Plex\ Media\ Scanner -l
Abort trap

Set PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR, now it works:

[plex@plex /usr/local/share/plexmediaserver]$ echo $PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR
/usr/local/plexdata/
[plex@plex /usr/local/share/plexmediaserver]$ ./Plex\ Media\ Scanner -l
  2: Movies
 22: Music
  1: TV

that’s odd its working fine here…

I mean if it works for you that way… great but it should still work w/o

Just to clarify is this on FreeNAS or FreeBSD? Host or Jail?

Is it possible that PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR is somehow set to something else by another script?

oh I just noticed you’re setting those in the shell it self, there could be another env vars messing with it I suppose, that’s likely it, but again if that works for you every time than stick with it, but I would add “HOME” too just in case.

Oh! I’ve certainly got nothing against the script, or against using all of the useful/necessary environment variables. I was trying to give a minimized example, to show that I need PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR too. Maybe I added to the confusion.

Non-minimized example, including env output for verification. :slight_smile:

$ cat start-new.sh
#!/bin/sh

export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"
ulimit -s 3000

export plexmediaserver_support_path="/usr/local/plexdata/"
export SUPPORT_PATH="${plexmediaserver_support_path}"
export HOME="${plexmediaserver_support_path}/Plex Media Server"
SCRIPT=$(readlink -f $0)
SCRIPTPATH=$(dirname ${SCRIPT})
export LD_LIBRARY_PATH="${SCRIPTPATH}/lib"
export PLEX_MEDIA_SERVER_HOME="${SCRIPTPATH}"
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export PLEX_MEDIA_SERVER_LOG_DIR="${plexmediaserver_support_path}/Plex Media Server/Logs"
export PYTHONHOME="${SCRIPTPATH}/Resources/Python"
export PATH="${SCRIPTPATH}/Resources/Python/bin:${PATH}"

echo && echo "### env now:" && env && echo

echo "### Trying to start Plex Media Scanner ..."
echo "### Command: \`./Plex\ Media\ Scanner -i -o47923\`"
echo
./Plex\ Media\ Scanner -i -o47923
echo "### ... done."
echo
sleep 5 

echo "########################"
echo "### Setting PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR ..."
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${plexmediaserver_support_path}"
echo && echo "### env now:" && env && echo

echo "### Trying to start Plex Media Scanner:"
echo "### Command: \`./Plex\ Media\ Scanner -i -o47923\`"
./Plex\ Media\ Scanner -i -o47923
echo
echo "###... done."

And the output:

root@plex:/usr/local/share # su - plex
$ cd /usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead/
$ ./start-new.sh 

### env now:
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
LANG=en_US.UTF-8
MAIL=/var/mail/plex
PATH=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead/Resources/Python/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/tmp/bin
LD_LIBRARY_PATH=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead/lib
PLEX_MEDIA_SERVER_LOG_DIR=/usr/local/plexdata//Plex Media Server/Logs
OLDPWD=/tmp
PWD=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead
TERM=xterm-256color
PLEX_MEDIA_SERVER_HOME=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead
HOME=/usr/local/plexdata//Plex Media Server
USER=plex
PYTHONHOME=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead/Resources/Python
SUPPORT_PATH=/usr/local/plexdata/
SHELL=/bin/sh
LC_ALL=en_US.UTF-8
plexmediaserver_support_path=/usr/local/plexdata/
BLOCKSIZE=K

### Trying to start Plex Media Scanner ...
### Command: `./Plex\ Media\ Scanner -i -o47923`

### ... done.

########################
### Setting PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR ...

### env now:
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
LANG=en_US.UTF-8
MAIL=/var/mail/plex
PATH=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead/Resources/Python/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/tmp/bin
LD_LIBRARY_PATH=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead/lib
PLEX_MEDIA_SERVER_LOG_DIR=/usr/local/plexdata//Plex Media Server/Logs
OLDPWD=/tmp
PWD=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead
TERM=xterm-256color
PLEX_MEDIA_SERVER_HOME=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead
HOME=/usr/local/plexdata//Plex Media Server
USER=plex
PYTHONHOME=/usr/local/share/PlexMediaServer-1.19.4.2935-79e214ead/Resources/Python
SUPPORT_PATH=/usr/local/plexdata/
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/usr/local/plexdata/
SHELL=/bin/sh
LC_ALL=en_US.UTF-8
plexmediaserver_support_path=/usr/local/plexdata/
BLOCKSIZE=K

### Trying to start Plex Media Scanner:
### Command: `./Plex\ Media\ Scanner -i -o47923`
Title: Airplane!
  Part: /mnt/jailshare/movies.radarr/Airplane! (1980)/Airplane! (1980) Bluray-1080p.mp4

###... done.

I’m curious if @habys is still around and could try with just $HOME or with your script or mine. I can’t imagine how my environment is causing this, but that might be a failure of imagination. :slight_smile:

It’s a FreeNAS 11.3-Stable system, but I’m not using the FreeNAS plugin. I’ve got a default jail and the FreeBSD version of Plex. 1.19.5.2916 and 1.19.4.2935 behave the same way.

Comparing against a Plex Media Scanner process that was launched by Plex itself, I think we were missing PLEX_MEDIA_SERVER_LOG_DIR but I don’t think that was our issue. I added it and it didn’t make a difference. That certainly does include PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR; it’s where I learned about it.

I don’t think EAE_ROOT and LIBVA_DRIVERS_PATH and FFMPEG_EXTERNAL_LIBS are needed except by the Transcoder and EAE processes.

Output from procstat -e ${pid}:

EAE_ROOT=/tmp/pms-d6741ebb-a0cc-47b4-ace2-03e734141f7e/EasyAudioEncoder
FFMPEG_EXTERNAL_LIBS=/usr/local/plexdata/Plex\ Media\ Server/Codecs/8d34ac9-3140-freebsd-x86_64/
GROUP=plex
HOME=/usr/local/plexdata/Plex Media Server
HOST=plex
HOSTTYPE=FreeBSD
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
LD_LIBRARY_PATH=/usr/local/share/plexmediaserver/lib
LIBVA_DRIVERS_PATH=/usr/local/share/PlexMediaServer-1.19.5.2916-4ebbedbaf/lib/dri
LOGNAME=plex
MACHTYPE=x86_64
OSTYPE=FreeBSD
PATH=/usr/local/share/plexmediaserver/Resources/Python/bin:/sbin:/bin:/usr/sbin:/usr/bin
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/usr/local/plexdata
PLEX_MEDIA_SERVER_HOME=/usr/local/share/plexmediaserver
PLEX_MEDIA_SERVER_LOG_DIR=/usr/local/plexdata/Plex Media Server/Logs
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
PLEX_MEDIA_SERVER_PIDFILE=/var/run/plex/plex.pid
PWD=/
PYTHONHOME=/usr/local/share/plexmediaserver/Resources/Python
RC_PID=195
SCRIPTPATH=/usr/local/share/plexmediaserver
SHLVL=1
SUPPORT_PATH=/usr/local/plexdata
USER=plex
VENDOR=amd
X_PLEX_TOKEN=NNoTokenForYouJ

Yeah all the extra stuff is for the transcoder, and the logs dir is optional too (It will also default to user $HOME/Logs, but you could use it to change the logs dir if you wanted.

1 Like

In case it was something “clever” :crazy_face: that I was doing, I created a brand-new FreeNAS Plex plugin instance. Copied start-new.sh over, changed plexmediaserver_support_path to /.

Abort trap if PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR isn’t set.