Libraries and settings gone after upgrade to 1.19

Hi,

Upgraded PMS from 1.18.6.2348 to 1.19.1.2589. That changed some stuff in regards of the init.d-script, and in turn, the “PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR” variable. Previously this was set to “/var/lib/plexmediaserver/Library/Application Support”, while now being set to “/usr/lib/plexmediaserver/Library/Application Support” (“var” versus “usr”).

Fixed that by moving the old folder, to where it now expects it to be.

PMS starts fine, however all of the libraries are gone, and many settings. One example being “Network -> LAN Networks”, which is present with a value in the Preferences.xml file (“LanNetworksBandwidth”).

I’m suspecting that it does not actually read/use that folder after all.

Any suggestions?

Same here, didn´t even try to fix it on my side and immediately rolled back to 1.18.9.

Please talk to me / show me ?

[chuck@lizum files.513]$ grep usr *
plexmediaserver.init:export PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
plexmediaserver.init:    pids="$(ps -ef | grep /usr/lib/plexmediaserver | grep -v grep | awk '{print $2}')"
plexmediaserver.service:Environment=PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
plexmediaserver.service:ExecStartPre=/bin/sh -c '/usr/bin/test -d "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" || /bin/mkdir -p "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}"'
plexmediaserver.service:export LD_LIBRARY_PATH=/usr/lib/plexmediaserver/lib; \
plexmediaserver.service:exec "/usr/lib/plexmediaserver/Plex Media Server"'
[chuck@lizum files.514]$ grep var *
grep: debian: Is a directory
plexmediaserver.default:# Uncomment and edit variables below as desired
plexmediaserver.default:#export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/var/lib/plexmediaserver/Library/Application Support"
plexmediaserver.init:# Set Crash Reporting identification variables
plexmediaserver.init:# Read configuration variable file if it is present
plexmediaserver.service:Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/var/lib/plexmediaserver/Library/Application Support"
[chuck@lizum files.515]$

My setup runs in an LXC container, so there is no systemd (only init).

Even though irrelevant, the content of “/etc/systemd/system/plexmediaserver.service” is pasted below. Keep in mind that this file has not changed since September 2019, so the upgrade did not alter this.

[Unit]
Description=Plex Media Server for Linux
After=network.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=LD_LIBRARY_PATH=/usr/lib/plexmediaserver
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 '/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

/etc/init.d/plexmediaserver when running 1.19.1.2589 (that does not work);

#!/bin/sh
### BEGIN INIT INFO
# Provides:          plexmediaserver
# Required-Start:    $remote_fs $syslog $networking
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Plex Media Server
# Description:       Plex Media Server for Linux,
#                    More information at http://www.plexapp.com
# Author:            Plex Packaging team
# Version:           1.4
### END INIT INFO

# Set Crash Reporting identification variables
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 \" )"

# Change these parameters in /etc/default/plexmediaserver
export PLEX_MEDIA_SERVER_USER=plex
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
export PLEX_MEDIA_SERVER_MAX_STACK_SIZE=3000
export PLEX_MEDIA_SERVER_TMPDIR=/tmp
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${HOME}/Library/Application Support"

echo "LOL: $(date)" > /tmp/testlol

# Read configuration variable file if it is present
[ -r /etc/default/plexmediaserver ] && . /etc/default/plexmediaserver

Running=$(ps -ef | grep 'Plex Media Server'| grep -v grep | wc -l)

case "$1" in
  start)
    if [ $Running -gt 0 ]; then
      echo "Plex is already running."
      exit 0
    fi

    if [ -f /etc/default/locale ]; then
      export LANG="$(cat /etc/default/locale | awk -F '=' '/LANG=/{print $2}' | sed 's/"//g')"
      export LC_ALL="$LANG"
    fi

    # Silently support PLEX_USER if provided as override
    if [ "$PLEX_USER" != "" ]; then
      export PLEX_MEDIA_SERVER_USER="$PLEX_USER"
    fi

    # Create AppSuppDir if not present
    if [ ! -d "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR" ]; then
      mkdir -p "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR"
      if [ $? -eq 0 ]; then
        chown "${PLEX_MEDIA_SERVER_USER}"."${PLEX_MEDIA_SERVER_USER}" "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR"
      else
        echo "ERROR: Couldn't create \"$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR\" "
        exit 1
      fi
    fi

    export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}/lib"
    export TMPDIR="${PLEX_MEDIA_SERVER_TMPDIR}"
    ulimit -s $PLEX_MEDIA_SERVER_MAX_STACK_SIZE

    # Add sleep - for those who launch with this script
    echo "Starting Plex Media Server. "
    su -m $PLEX_MEDIA_SERVER_USER -s /bin/sh -c "exec ${PLEX_MEDIA_SERVER_HOME}/Plex\ Media\ Server &" >/dev/null 2>&1
    sleep 3
    ;;

  stop)
    if [ $Running -eq 0 ]; then
      echo "Plex Media Server is not running."
      exit 0
    fi
    echo "Shutting down Plex Media Server: "

    # Ask nicely
    pids="$(ps -ef | grep 'Plex Media Server' | grep -v grep | awk '{print $2}')"
    kill -15 $pids

    sleep 5

    # Stuck
    pids="$(ps -ef | grep /usr/lib/plexmediaserver | grep -v grep | awk '{print $2}')"

    if [ "$pids" != "" ]; then
      kill -9 $pids
    sleep 2
    fi
    ;;

  restart)
    $0 stop
    sleep 5
    $0 start
    ;;

  status)
    if [ $Running -gt 0 ]; then
      echo "Plex Media Server is running."
    else
      echo "Plex Media Server is stopped."
    fi
    ;;

  *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
	;;
esac

exit 0

/etc/init.d/plexmediaserver when running 1.18.6.2348 (that does work);

#!/bin/sh
### BEGIN INIT INFO
# Provides:          plexmediaserver
# Required-Start:    $remote_fs $syslog $networking
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Plex Media Server
# Description:       Plex Media Server for Linux,
#                    More information at http://www.plexapp.com
# Author:            Plex Packaging team
# Version:           1.3
### END INIT INFO

# Read configuration variable file if it is present
[ -r /etc/default/plexmediaserver ] && . /etc/default/plexmediaserver

IsRunning=$(ps -ef | grep 'Plex Media Server'| grep -v grep | wc -l)

case "$1" in
  start)
    if [ $IsRunning -gt 0 ]; then
      echo "Plex is already running."
      exit 0
    fi

    echo "Starting Plex Media Server. "
    su -l $PLEX_MEDIA_SERVER_USER  -s /bin/sh -c "/usr/sbin/start_pms &" >/dev/null 2>&1
    sleep 3
    ;;

  stop)
    if [ $IsRunning -eq 0 ]; then
      echo "Plex Media Server is not running."
      exit 0
    fi
    echo "Shutting down Plex Media Server: "

    # Ask nicely
    pids="$(ps -ef | grep 'Plex Media Server' | grep -v grep | awk '{print $2}')"
    kill -15 $pids

    sleep 5

    # Stuck
    pids="$(ps -ef | grep /usr/lib/plexmediaserver | grep -v grep | awk '{print $2}')"

    if [ "$pids" != "" ]; then
      kill -9 $pids
    sleep 2
    fi
    ;;

  restart)
    $0 stop
    sleep 5
    $0 start
    ;;

  status)
    if [ $IsRunning -gt 0 ]; then
      echo "Plex Media Server is running."
    else
      echo "Plex Media Server is stopped."
    fi
    ;;

  *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
	;;
esac

exit 0

Content of /usr/sbin/start_pms when running 1.18.16.2348;

#!/bin/sh
#
# Plex Media Server - Manual start script.
#

# Set Crash Reporting identification variables
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 \" )"

# Change these parameters in /etc/default/plexmediaserver
export PLEX_MEDIA_SERVER_USER=plex
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
export PLEX_MEDIA_SERVER_MAX_STACK_SIZE=3000
export PLEX_MEDIA_SERVER_TMPDIR=/tmp
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${HOME}/Library/Application Support"

if [ -f /etc/default/locale ]; then
  export LANG="$(cat /etc/default/locale|awk -F '=' '/LANG=/{print $2}'|sed 's/"//g')"
  export LC_ALL="$LANG"
fi

test -f /etc/default/plexmediaserver && . /etc/default/plexmediaserver

# Silently support PLEX_USER if provided as override
if [ "$PLEX_USER" != "" ]; then
  export PLEX_MEDIA_SERVER_USER="$PLEX_USER"
fi

# Create AppSuppDir if not present
if [ ! -d "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR" ]; then
  mkdir -p "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR"
  if [ ! $? -eq 0 ]; then
    echo "ERROR: Couldn't create $PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR "
    exit 1
  fi
fi

export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}/lib":"${PLEX_MEDIA_SERVER_HOME}"
export TMPDIR="${PLEX_MEDIA_SERVER_TMPDIR}"

ulimit -s $PLEX_MEDIA_SERVER_MAX_STACK_SIZE

# Add sleep - for those who launch with this script
sleep 3

(cd /usr/lib/plexmediaserver; ./Plex\ Media\ Server)

Since “/var/lib/plexmediaserver/” doesn’t seem to be present in the init.d-file for 1.18.6.2348, but PMS successfully uses the content of “/var/lib/plexmediaserver” regardless, I’m going to assume that there is some hardcoded path or similar, somewhere else in the Plex files, that is changed between 1.18.6.2348 and 1.19.1.2589.

What happened to the /usr/sbin/start_pms script in 1.19.1.2589? It is missing in this beta release.

It is removed, as the logic contained within it, is moved into the init.d-script itself (as you can see by the content of those files that I posted in my previous comment).

Got it! Thanks for helping me see more clearly.

Well that’s no fun for my build as I use the start_pms script to run plexmediaserver on Slackware LXC. I copied the script from my previous build and i’m able to run 1.19.1.2589.

Please help me figure out what doesn’t work for you with regard to /etc/init.d/plexmediaserver in 1.18.9 ?

What I’ve done is taken out start_pms script because /etc/init.d/plexmediaserver is now the full functionality of both in one. start_pms was redundant.

start_pms was a fully manual-start script from long long ago.
/etc/init.d/plexmediaserver is the full init-based service control. Calling /etc/init.d/plexmediaserver manually has the same result.

Did I omit something?

This should be nothing more than shifting the invocation to /etc/init.d/plexmediaserver start and the variables in /etc/defaults/PlexMediaServer. (proper SYSV style)

Supplemental info:

In 1.19.1, When I recognize a container is being used:

  1. Is it Docker? If so - they get their special handling
  2. Is it official lxc (cat /proc/1/environ contains container=lxc) ? I do this to bypass a known bug in udevadm inside a container.
  3. Is it systemd or init?
  4. Anything else is deemed custom - to which I give you total control.

You are right that there should be no difference between the "/etc/init.d/plexmediaserver + start_pms" -combo (in 1.18) and the new /etc/init.d/plexmediaserver in 1.19 (that has the logic of start_pms). I just assumed that this was the issue, before I actually looked at the content within the init.d-script of 1.18.

Where does /var/lib/plexmediaserver come into the picture? This was the library path before, and works in 1.18, even though all paths in both /etc/init.d/plexmediaserver and start_pms points to /usr/lib/plexmediaserver. I can see that it’s present in the /etc/systemd/system/plexmediaserver.service file, but that is never used when using init (which is the case for me).

How I do this is:

  1. The default HOME directory for user plex is /var/lib/plexmediaserver.
  2. I use this as the foundation then supersede using /etc/default/plexmediaserver if you’ve customized and moved the APPLICATION_SUPPORT_DIR elsewhere (due to space)
[chuck@lizum files.516]$ grep plex /etc/passwd
plex:x:999:999::/var/lib/plexmediaserver:/usr/sbin/nologin
[chuck@lizum files.517]$ 
# Change these parameters in /etc/default/plexmediaserver
export PLEX_MEDIA_SERVER_USER=plex
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
export PLEX_MEDIA_SERVER_MAX_STACK_SIZE=3000
export PLEX_MEDIA_SERVER_TMPDIR=/tmp
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${HOME}/Library/Application Support"

# Read configuration variable file if it is present
[ -r /etc/default/plexmediaserver ] && . /etc/default/plexmediaserver

I don’t hard code it now. It’s fully free-floating,
a. $HOME
b. Default $APP_SUPP_DIR
c. /etc/default (override)

You can either set the override or use the $HOME variable for the username (default being plex) that PMS is running as.

Supplemental:

My thinking behind this is:

  1. If you run PMS as user plex – use the established default of /var/lib/plexmediaserver

  2. If you run PMS as your username – use your home directory as the default.

  3. Suspecting you’ll not want it in your home directory, you’ll override PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR and put it where you want.

Does this say it better?

I run it in LXC-container, with only init (no systemd). It’s run as the user plex, that has /var/lib/plexmediaserver set as the home folder. I’ve never specified any overrides for path in /etc/default/plexmediaserver. In 1.18 it works, in 1.19 it does not work. If I upgrade to 1.19, it stops working. If I downgrade to 1.18, it immediately starts working. This is repeatable/reproducible.

I’m pretty sure that combining /etc/init.d/plexmediaserver and start_pms broke it. The variables that you export in start_pms is available when you launch PMS with ./Plex\ Media\ Server. However, when you launch it via the su command, it does not work;

root@tardis:~# export TEST_VAR=foo
root@tardis:~# su -m plex -s /bin/sh -c echo "${TEST_VAR}"

root@tardis:~#

The above mimics what you essentially do with the init.d-script in 1.19, which clearly does not seem to work as intended (i.e. the PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR variable is never available in that shell).

The -m option is what does preserve the environment.

From man su:

       -m, -p, --preserve-environment
              Preserve the entire environment, i.e. it does not set HOME, SHELL, USER nor  LOG‐
              NAME.  This option is ignored if the option --login is specified.

If this isn’t working for you, we need to dig deeper.

Ah, slight typo in my example above;

root@tardis:~# export TEST_VAR=foo
root@tardis:~# su -m plex -s /bin/sh -c "echo ${TEST_VAR}"
foo
root@tardis:~#

However, I found the real culprit. In 1.18 you launch start_pms as the plex user, causing export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${HOME}/Library/Application Support" to become /var/lib/plexmediaserver/Library/Application Support.

In the init script of 1.19, you run the export in the init-file (which is run as the root user), causing PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR to become /root/Library/Application Support.

This is also confirmed by the fact that I now have the /root/Library/Application Support folder (created just after I did my first upgrade to 1.19).

Oh draaaatts. I did not see that one. :thinking:

Looks like

export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${HOME}/Library/Application Support"

needs to effectively become

export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${PLEX_MEDIA_SERVER_USER_HOME}/Library/Application Support"

meaning that I need evaluate the runtime user before the launch ?

If there is concurrence, this will remedy that one variable.

$ export PLEX_USER=plex
$ grep "$PLEX_USER" /etc/passwd | awk -F: '{print $6}'
/var/lib/plexmediaserver
$ 

I maintain the floating nature of the control mechanism by evaluating just prior to launch.

If all are agreed, I’ll modify /etc/init.d/plexmediaserver and issue the patch here.
Concurrently, I will make the change to the source package scripts and push them up for inclusion in the next PMS release.

You could change the current part;

# Change these parameters in /etc/default/plexmediaserver
export PLEX_MEDIA_SERVER_USER=plex
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
export PLEX_MEDIA_SERVER_MAX_STACK_SIZE=3000
export PLEX_MEDIA_SERVER_TMPDIR=/tmp
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${HOME}/Library/Application Support"

… with this;

# Change these parameters in /etc/default/plexmediaserver
export PLEX_MEDIA_SERVER_USER=plex
# Silently support PLEX_USER if provided as override
if [ "$PLEX_USER" != "" ]; then
  export PLEX_MEDIA_SERVER_USER="$PLEX_USER"
fi
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
export PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
export PLEX_MEDIA_SERVER_MAX_STACK_SIZE=3000
export PLEX_MEDIA_SERVER_TMPDIR=/tmp
PLEX_USER_HOME=`eval echo "~${PLEX_MEDIA_SERVER_USER}"`
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${PLEX_USER_HOME}/Library/Application Support"

(and remove that PLEX_USER logic in the start-section)

I incorporated PLEX_USER at the request of several of the fan-based SYSV-init groups out there.

They had their own launch mechanisms all based on PLEX_USER.
I didn’t see any harm in accommodating the compatibility to use it if present.