Works in bash but not from SystemD, looking for ideas as to why

Server Version#: OpenSUSE 15.0
Player Version#: Not Sure but not relevant

So this is a little strange but I started to change my Library paths because I reorganized things and my PlexMediaServer crashed. After that when I tried to start it I could not connect even though it said it was running just fine.

So I spent quite a long time trying to figure it out and eventually found out that that if I put the equivalent script in a bash file to what was in PlexMediaServer.service and run the bash file it works just fine.

I haven’t any ideas on why all this happened except perhaps before I started changing library paths some sort of caching was keeping things going fine but once whatever that caching was got cleared it no longer worked… but that’s just speculation.

The facts are as follows…

This runs but I cannot connect which is used when I run service plexmediaserver start and is just the default script that is created when you install the Plex server:

[Unit]
Description=Plex Media Server
After=network.target network-online.target

[Service]
Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/var/lib/plexmediaserver/Library/Application Support"
Environment=PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
Environment=PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
Environment=PLEX_MEDIA_SERVER_TMPDIR=/tmp
Environment=LC_ALL=en_US.UTF-8
Environment=LANG=en_US.UTF-8
ExecStartPre=/bin/sh -c '/usr/bin/test -d "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" || /bin/mkdir -p "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}"'
ExecStart=/bin/sh -c '\
PLEX_MEDIA_SERVER_INFO_VENDOR="$(grep ^NAME= /etc/os-release | awk -F= "{print \\$2}" | tr -d \\" )" \
PLEX_MEDIA_SERVER_INFO_DEVICE="PC" \
PLEX_MEDIA_SERVER_INFO_MODEL="$(uname -m)" \
PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION="$(grep ^VERSION= /etc/os-release | awk -F= "{print \\$2}" | tr -d \\" )" \
LD_LIBRARY_PATH=/usr/lib/plexmediaserver/lib \
"/usr/lib/plexmediaserver/Plex Media Server"'
Type=simple
User=plex
Group=plex
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3

[Install]
WantedBy=multi-user.target

However, when I create an equivalent script in bash and run it connecting is no problem and everything works perfectly AFAICT. Here is the script I wrote that is working:

#!/bin/sh

sudo -u plex \
export LANG='en_US.UTF-8'; \
export LC_ALL='en_US.UTF-8'; \
export LD_LIBRARY_PATH='/usr/lib/plexmediaserver/lib'; \
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR='/srv/multimedia/plexmediaserver/Library/Application Support'; \
export PLEX_MEDIA_SERVER_HOME='/usr/lib/plexmediaserver'; \
export PLEX_MEDIA_SERVER_INFO_VENDOR="$(grep ^NAME= /etc/os-release | awk -F= "{print \$2}" | tr -d \" )"; \
export PLEX_MEDIA_SERVER_INFO_DEVICE="PC"; \
export PLEX_MEDIA_SERVER_INFO_MODEL="$(uname -m)"; \
export PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION="$(grep ^VERSION= /etc/os-release | awk -F= "{print \$2}" | tr -d \" )"; \
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6; \
export PLEX_MEDIA_SERVER_TMPDIR='/tmp'; \
"/usr/lib/plexmediaserver/Plex Media Server"

The only thing I can think of is that maybe a system upgrade added some new Linux security feature that’s on by default that I don’t know about which is affecting Plex starting through systemd but again, that’s just speculation, perhaps someone knows something for real?

Your output above shows why it doesn’t work:

  1. Plex defaults to /var/lib/plexmediaserver/Library/Application Support
  2. You use a different location. (/srv/multimedia/plexmediaserver/Library/Application Support)
  3. I always overwrite the service file in /lib/systemd/system with each update.

To resolve this, you only need to create a configuration override file (normal systemd) operation.

In /etc/systemd/system/plexmediaserver.service.d/override.conf,

Place the following text

#
# Move Application Support directory location
#
[Service]
Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/srv/multimedia/plexmediaserver/Library/Application Support"
#
#

Save this file then activate it with

systemctl daemon-reload
systemctl restart plexmediaserver

Now systemd will again work for you.

This customization will not be touched when PMS updates. There is no need for me to touch your custom configuration files.

The override was good to handle system updates but it wasn’t the underlying problem. When I moved the data files some, not many but a few files got a different ownership and that was the cause. Once I made all moved files owned by the user “plex” again it worked fine again. It would have been nice to have a “can’t read file” message somewhere but oh well.

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