PMS stopped honoring temporary directory setting. Now uses /tmp

As I said above, we’re going to clean up the confusion caused in the new packaging.

Having traced it all down back to the beginning of time (2011) for Linux.

  1. TMPDIR was always used (for POSIX compliance)
  2. TranscoderTempDir is not set by default. If you want that, you can set in Preferences.xml or in the GUI (transcoder - show advanced)

When PMS was first ported to Linux and the team setup the variables, they made plans for having all nice names. PLEX_MEDIA_SERVER_TEMPDIR was supposed to be included.

In the initial start_pms script, it was used, if defined, by

TMPDIR="$PLEX_MEDIA_SERVER_TMPDIR"

The transition from SYSV -> Upstart -> systemd lost that functionality in systemd.

When I re-introduced SYSV-init support, I accidentally brought it back.
It was never supported in the first place.

Official has always been to set TMPDIR, or any of the four honored by mkstemp() prior to PMS launch .

What will happen now is I’m going to clean up this perpetuation of an error because there is no way for us to selectively pick variable names in service definitions.

The solution I’m going to implement is:

  1. I’ll set TMPDIR to the Plex default (which is per each platform’s default) /tmp
  2. If this isn’t desired, all that’s needed is to declare a new value in override.conf or /etc/default/plexmediaserver (platform dependent)

I will also be adding some support info in the service file and default file to clarify this.

1 Like

Ah! I just noticed I had a lingering file in my /etc/sysconfig for Plex. I guess it was in the package a long time ago. I had renamed it to /etc/sysconfig/PlexMediaServer.prev (note the capital letters). It was dated April 2013! I didn’t think to look there because it wasn’t referenced in the .service file. Like you stated, it has this:

PLEX_MEDIA_SERVER_TMPDIR="/plex/tmp"
export TMPDIR="${PLEX_MEDIA_SERVER_TMPDIR}"

So setting that var it did work a long time ago! I set it and forgot about it and now the file isn’t used anymore.

Are any of those other environment variables in that ancient file used anymore?

Thanks for getting this all cleaned up.

There you go. That is the exact evidence we found.

PLEX_MEDIA_SERVER_TMPDIR was supported via the shell script only.
It was supposed to become a “pretty” variable in PMS but never did.

Transition from 2013 → 2015 (upstart) → 2016 (system)

The introduction of upstart broke it. systemd was also broken but perpetuated the broken variable nonetheless.

When I recreated SYSV-init support, from the old archives, I encountered that variable and, without realizing it didn’t belong, integrated support for it.

Jump forward in time until today.

As the result of all the research.

  1. TMPDIR, TEMPDIR, TMP, and TEMP remain variables supported by Linux
  2. Plex uses, and has always only used TMPDIR
  3. Engineering decision is to remove the non-supported PLEX_MEDIA_SERVER_TMPDIR variable from Linux desktop distributions (redhat & debian).

Here’s what’s most likely coming in 1.19.5 (when I get this through QA – it’s too late for PMS 1.19.4 which is already in the pipe.)

What I am sharing here is subject to my and QA testing so please forgive any “fat fingered” code :rofl:

Redhat plexmediaserver.service file

#
# Plex Media Server's variables can be customized by creating:  /etc/systemd/system/plexmediaserver.service.d/override.conf

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

[Service]
# Customizable environment variables
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=TMPDIR=/tmp

# User and group to run Plex as (customizable in override.conf)
User=plex
Group=plex

# PMS startup
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  \
 exec "/usr/lib/plexmediaserver/Plex Media Server"'

# Service control
Type=simple
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
SyslogIdentifier=Plex Media Server
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

Debian plexmediaserver.service file

#
# Plex Media Server's variables can be customized by creating:  /etc/systemd/system/plexmediaserver.service.d/override.conf


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

[Service]
# Customizable environment variables
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=TMPDIR=/tmp

# User and group to run Plex as (customizable in override.conf)
User=plex
Group=plex

# PMS startup
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 '\
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 LD_LIBRARY_PATH=/usr/lib/plexmediaserver/lib; \
exec "/usr/lib/plexmediaserver/Plex Media Server"'

# Service control
Type=simple
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
SyslogIdentifier=Plex Media Server
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

The discrepancy is because Redhat is very strict on SELinux out of the box.
They are otherwise identical.

*/etc/init.d/plexmediaserver (changed section)

    # Check TempDir per ISO/IEC 9945: TMPDIR, TMP, TEMP, TEMPDIR
    Candidate=""
    if   [ "$TMPDIR" != "" ]; then
      Candidate="$TMPDIR"

    # Be generous with TEMP DIR specification
    elif [ "$TMP" != "" ]; then
      Candidate="$TMP"

    elif [ "$TEMP" != "" ]; then
      Candidate="$TEMP"

    elif [ "$TEMPDIR" != "" ] && [ -d "$TMP" ]; then
      Candidate="$TEMPDIR"
    fi

with

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

It’s clear I have a great deal more flexibility in any shell environment but I need adhere to lowest common denominator else there will be complete mayhem.

1 Like

Looks good. It is good to know that the var’s have been vetted.

My only small criticism is that the note “(customizable in override.conf)” could apply to anything in the .service file, not just User= and Group=. The note could be placed at the beginning of the file to give a hint to users unfamiliar with that feature of systemd.

I am having this same issue. Is there an ETA when this will be resolved?

You can use the proper variable TMPDIR, now.

PLEX_MEDIA_SERVER_TMPDIR never was.

With the next update, I will stop reporting it in the config.
To aid in the transition, I will flag PLEX_MEDIA_SERVER_TMPDIR as a not-allowed variable.

Hey guys,

did anyone ask the question why Plex is writing >1 GiB temporary data at all and if this was the case before already? Writing such amount to any tmpfs OR disk is neither something I like to see from a media server within a day single client usage, and since we never faced issues like this before and never touched any tmp path settings, I guess it was using much less before.

Is there probably an issue with internal tmp cleanup tasks?

1 Like

show me what’s happening please? (directory listing)

The new intro skipping will be doing a fair amount of reading and writing.

We only got this report just as well, I’m building a test case up, requires video files, at least playing audio files does not lead to any tmp files being created. Conversion to RAW seems to be what is creating the large ones.


… probably indeed due to skip intro feature, something I cannot test due to missing Plex pass for now :wink:. Thanks for the hint!


Found Lots of traffic in /tmp on intro detection - #3 by ChuckPa, jep that’s it.


Went through the thread and see it has been closed. But I have to say the discussion opposition has a fair point that the current situation where intro detection writes such amount of data by default to /tmp creates real issues. See: Image update | Odroid XU3/XU4/MC1/HC1/HC2 · Issue #3544 · MichaIng/DietPi · GitHub
On the new GitHub issue one can see that disabling intro detection solved the issue of > 1 GiB PMS data written to /tmp, default TMPDIR and by default tmpfs with again default 512 MiB size on all Linux distros I know. Of course one can increase it, on our little overlay distro it has 1 GiB by default but more stresses a swap file on most SBCs, hence often leads to SD card wear that way. Using a well defined directory, respecting a setting dedicated to TMPDIR instead (like it is for regular transcoding), allows one to have that data created e.g. on an external drive so that neither GiBs of RAM is blocked nor the SD card is worn. Otherwise the feature IMO should be disabled by default with a strong warning that it requires a certain (unusual) large amount of RAM in certain circumstances. I just have this one report of 1 GiB, but don’t know much much media was processed and how much data would have been written if /tmp wouldn’t gotten full.

Read somewhere that the feature will be available for non-pass users as well? Would run some tests then to check more in detail myself.


Little buttom line from my end:

  • The default tmpfs size is 512 MiB and /tmp is a tmpfs usually.
  • That gives a hint about which data size is usually expected to be created there and in which case one should better use a dedicated non tmpfs dir by default, also /var/tmp is an option, which is considered for persistent tmp files, hence not intended to be a tmpfs.
  • I know there is no strict rule about this, but the related issues are present. So IMO its wise to design program defaults a way that no 512 MiB are written to /tmp in usual circumstances with default settings :slightly_smiling_face: .

I’ve corrected the Debian installer to:

  1. No longer allow the unsupported PLEX_MEDIA_SERVER_TMPDIR variable.

I do have a bit of a problem, IMO, with a SBC hobbyist board driving design. Please compare that with much larger systems (e.g TVS-1282T-i7-32GB)

When I have a 30GB file, should that DietPi ARMv8 be able to handle it without question?

The solution there is to manage TMPDIR and place it where it won’t destroy the SD card.

A better place for it to be would be in /var/lib/plexmediaserver/tmp_transcoding, wouldn’t it?

A better place would be to just use the TranscoderTempDirectory
whistle

and where might that be By Default ???
Default is TMPDIR

whistles back :wink:

FYI: we’ll iterate to a solution. I’m not giving you a hard time. I am simultaneously asking you to help me make a case to Engineering.

By default the TranscoderTempDirectory is currently /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode
What a perfect place to put temporary files produced by the Transcoder :slight_smile:

I can do that: :slight_smile:

TMPDIR=“${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}/Plex Media Server/Cache/Transcode”

Like that?

That is a workaround, yes.

But the Proper solution would be the Transcoder just respecting writing to TranscoderTempDirectory and not using TMPDIR. It uses TranscoderTempDirectory for most of its operations now anyways.

I suspect we’re looking at a bug in PMS itself which is manifesting in TMPDIR.
I think you’re feeling the same way.

The new “Skip Intro” feature is making a mess because it’s not writing where it belongs.

plausible?

YES!!! This is what i have been saying for 2 days now :slight_smile:

I’m sorry. so VERY sorry. what can I say? I’m a redhead ?

When you back down to a previous version, all behavior is normal?