Debian (Ubuntu) install - env not set up for plex's CLI? (no such column: library_sections.content_changed_at)

Server Version#: 1.22.1.4228 (but probably has been an issue for a while)
Player Version#: N/A

I came across the same issue as this forum post (calling PMS Scanner from CLI gave a weird error about a database column being nonexistent, even though it is an incorrect error message).

However, when checking the schema of the tables, there was no issue with the database whatsoever, albeit the scanner CLI saying that it couldn’t find a column (I don’t think there was an issue in the original post either, just misinterpretation of default values in sqlite3).

After some searching, I found this fix here. To copypasta in case the link goes down some day,

export LD_LIBRARY_PATH=/usr/lib/plexmediaserver:/usr/lib/plexmediaserver/lib
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/var/lib/plexmediaserver/Library/Application\ Support

before running your scanner. Perhaps set the rest of the env vars as listed in the service (see sudo systemctl cat plexmediaserver.service on modern debian, or /usr/lib/plexmediaserver/) as well just in case for other uses.

Which means that either

  • tools like the scanner, crash uploader, and any other tools that are meant to be called from the command line, can’t in some Linux distributions because some configuration is not being installed

  • the tools mentioned aren’t supposed to rely on these variables / their default (when the env is non-existent) values are incorrect on (at least) Ubuntu 20.04

  • When things switched to systemd devs decided to put the environment set up in a service for the account, rather than the account itself, by accident.

  • the fact that you have to manually set this up is undocumented / hard to find

In either case that error is just weird. It seems as though database existence isn’t checked.

There’s also a very weird empty folder created - “/usr/lib/plexmediaserver/’.”, as in the last leaf in that path is '.

This is less of a “hey help me” post and more of a “hey here’s something that seems to incorrect and I can’t tell which / why, it should probably be fixed / documented”, in case someone else comes along spending several hours screaming at the sky as to why they can’t run the scanner from the CLI and can’t fix the database.

  1. The scanner and crash uploader, while being present and callable, are primarily invoked from within PMS. PMS has the environment variables already set from when it was launched as user plex. Those two programs only need the remainder of their command line options.

  2. Thanks for alerting to the stray subdirectory. I found where it’s occurring and let the build team know.

  3. As for how the base environment is configured, I configured it how systemd said to. I passed the environment variables in the base service file.

  4. Variables were previously defined in /etc/default/plexmediaserver in the ‘init’ system. Now I define them where systemd wants them. The installer supports init and systemd on Debian/Ubuntu systems.

  5. Custom overrides can be created /etc/systemd/system/plexmediaserver.service.d/override.conf

1/3/4: As the user plex, at least on Ubuntu 20.04, those environment variables are not persisting to new login sessions nor via sudo su - plex after the service file has been executed.

This causes the scanner to create a new “Library” directory (normally existing in /var/lib/plexmediaserver/Library) at $HOME/Library, and then subsequently fails with the error I mentioned (because the database doesn’t even exist in this new library yet, let alone the fact that the table doesn’t have the appropriate column, but it is a super weird error for what it is).

This behavior occurs for all users, including the user plex / whichever user is set in the systemd script. (point 5 I know).

I only mention this because the documentation states that the scanner can be executed manually. As for why I wanted to execute the scanner manually in the first place, it’s a long story and probably irrelevant, however executing the scanner manually was the simplest forseeable solution I could think of for the conundrum I was having.

Whether or not the suggestion is taken, it may be better a good idea to add a /home/plex/.plexrc file and then append to /home/plex/.bashrc

# .plexrc
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/var/lib/plexmediaserver/Library/Application Support"
export PLEX_MEDIA_SERVER_HOME="/usr/lib/plexmediaserver"
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export PATH="${PLEX_MEDIA_SERVER_HOME}${PATH:+:$PATH}"
# ...other variables if they are necessary for manual execution of the scanner
# .bashrc - append
# Add plex env variables for the scanner
if [ -f "$HOME/.plexrc" ]; then
    . "$HOME/.plexrc"
fi

Further, if stuff like the os and os version is only needed in the systemd script, instead of being executed via reading /etc/os-release the recommendation if I recall correctly is to use specifiers.

There’s also an issue in linking using LD_LIBRARY_PATH as shown, specifically, because other ubuntu libraries expect newer versions of libstdc++ and therefore cause an error. For example:

I don’t know if Plex’s team modified libstdc++, but if they don’t, they really shouldn’t be redistributing it / packaging it in a manner that use breaks other libraries. In the worst case as far as I know static linking is considered “legal” even with proprietary software for libstdc++. If the redistribution as shown is necessary, then it should be documented that on Linux systems that the above variables need to be set to use the scanner from the CLI, and only during use, not all the time.

  • User plex is NOT a login account. It is a service account. I configure it that way when created. I have structured it such that the service file provides all necessary environment variables when PMS starts.

  • sudo su - plex is the wrong way to invoke that.

  1. You’re invoking sudo (jump to root) to do a su - to an account .
  2. You didn’t specify a shell which tells me you have modified /etc/passwd.
  • I’m sorry but I will not add /home/plex or any such files. Plex’s $HOME will remain /var/lib/plexmediaserver (as directed by Engineering). User plex will remain a system account (please notice the UID/GID it was created with which clearly identifies it as such as well as the nologin shell specification.

If you wish to have a login account for such purposes, my recommendation is to overload the UID & GID as you create the new interactive shell account.

Then, in that .bashrc or .profile, you can assert the variables which are needed with the values to match your local configuration.

Plex’s $HOME will remain /var/lib/plexmediaserver (as directed by Engineering).

Okay so this might be something that I’ve messed up then, before installing plex. Before installation I had made a plex account in order to set up my media. The installation didn’t warn me (edit: or if it did, I did not see it) that the account as it was set up was invalid, nor did installation overwrite the user settings of the account.

What is the meant-to-be line in /etc/passwd?

That DEFINITELY will mess it up

On a perfectly clean system, it should end up as this

chuck@ubuntu:~/Downloads$ grep plex /etc/passwd
plex:x:998:998::/var/lib/plexmediaserver:/usr/sbin/nologin
chuck@ubuntu:~/Downloads$ 

UID/GID might fluctuate a bit depending on any other --system accounts which were created first.

You do raise a valid point which I’m not sure if I should address:

“What if there is an existing plex user and it’s not configured correctly? Do I trust what the user has done or complain?”

Ah okay, that makes sense at least. With $HOME being /var/lib/plexmediaserver, by default the scanner looks at $HOME/Library, which means if someone sudo su’d (the jump to root is necessary in my case and many others usually) via something like sudo su - plex --shell=/bin/bash, then everything should theoretically work appropriately.

It’s just because the plex user was preconfigured by me (incorrectly, the main issue is the wrong $HOME) that tools like the scanner were being odd.

Personally I would say to at least warn about the $HOME not being set correctly (if anything else, it would stop there from being another confused user like me).

AFAIK system vs non-system is a matter of organization (in which UID/GID range, which itself the default varies by Linux distribution), not anything relevant that would block the package from working. The change in shell or comment also AFAIK wouldn’t cause any ill effects.

This shouldn’t be checked via reading /etc/passwd though, because of some more “advanced systems”-- I would instead use getent passwd user | cut -d: -f6, replacing “user” with whatever is set in the deb / during installation.

Thanks for your input.

I think I know how I’m going to handle it.

  1. Given Debian (+ Ubuntu) and Redhat (Centos + Fedora) support --system, I will continue to use that.

  2. Given users might want to move PMS home directory instead of using a systemd-supported override, I’ll try to figure out how to support both concurrently as it could be tricky.

  3. I will add detection. It’s pretty easy

bash-5.0$ [ "$(getent passwd plex | awk -F: '{print $7}' | grep 'sh$')" ] && echo "Has Shell"
Has Shell
bash-5.0$ getent passwd plex
plex:x:977:969::/var/lib/plexmediaserver:/bin/bash
bash-5.0$

This is an easy test to perform and I can set a warning for both distro families.

1 Like

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