Linux: User and Storage configuration

 
When running Plex Media Server on Linux distributions its possible to change what user Plex runs as and where it stores the metadata.

CentOS / Fedora / SUSE / Ubuntu


Changing the defaults

When installing the RPM/deb package, default configuration files are added to accommodate a number distributions. Fedora 15, CentOS 7, SUSE 12.1, Ubuntu 15.04 and newer releases of these are systemd based, CentOS 6/RHEL6 and Fedora 14 are systemV based. For systemd based platforms there resides a service file with configuration settings named plexmediaserver.service and for CentOS6/RHEL6 and Fedora 14 the configuration is stored in a sysconfig file named PlexMediaServer.
 
CentOS6/RHEL6 Fedora 14 Config:
To change config settings for Plex please edit /etc/sysconfig/PlexMediaServer
For changeing where Plex Media Server places its metadata files comment out in /etc/sysconfig/PlexMediaServer:

# PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/opt/plex/Library/Application Support"

You can edit the path within the quotationmarks to any directory of your choice. The path you put in there has one requirement. That you ensure that the user you run Plex Media Server as owns it. Default is the user plex. The directory you define has to exisit eg /opt/plex/Library/Application Support” has to be in place and owned by plex. Remember to chown plex on the dir you choose.

For changing the usercontext under which Plex Media Server runs as change the variable PLEX_USER in the beginning of the config file. When changing the user remember to change the ownership of your Plex Media Server’s Application Support Dir. So as an example if you are changing from the user plex to user awesomeuser then remember to run: chown -R awesomeuser /var/lib/plexmediaserver

If you changed the PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR setting in the config file then substitute /var/lib/plexmediaserver with that. So if it was /opt/plex/Library/Application Support, then the command would be: chown -R awesomeuser /opt/plex
The default config file looks like this:

# Plex Media Server Config file.
 
# Set Plex User
PLEX_USER=plex
# Set home of Plex Media Server 
PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
 
# Set home for Plex metadata
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="`getent passwd $PLEX_USER|awk -F : '{print $6}'`/Library/Application Support"
 
# the number of plugins that can run at the same time
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
 
# ulimit -s $PLEX_MEDIA_SERVER_MAX_STACK_SIZE
PLEX_MEDIA_SERVER_MAX_STACK_SIZE=10000
 
# ulimit -l $PLEX_MEDIA_SERVER_MAX_LOCK_MEM
PLEX_MEDIA_SERVER_MAX_LOCK_MEM=3000
 
# ulimit -n $PLEX_MEDIA_SERVER_MAX_OPEN_FILES
PLEX_MEDIA_SERVER_MAX_OPEN_FILES=4096
 
# where the mediaserver should store the transcodes
PLEX_MEDIA_SERVER_TMPDIR=/tmp
 
# Enable syslog for Plex logging.
# uncomment to enable
# export PLEX_MEDIA_SERVER_USE_SYSLOG=true
 
# uncomment to set it to alternative support dir, eg. /opt/plex
# NOTE: Plex user must be able to write to this dir
#
# PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/opt/plex/Library/Application Support"
 
export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}"
export TMPDIR="${PLEX_MEDIA_SERVER_TMPDIR}"
export PLEX_MEDIA_SERVER_HOME=$PLEX_MEDIA_SERVER_HOME
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=$PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS
export PLEX_MEDIA_SERVER_TMPDIR=$PLEX_MEDIA_SERVER_TMPDIR
export LD_LIBRARY_PATH=$PLEX_MEDIA_SERVER_HOME
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"
ulimit -l $PLEX_MEDIA_SERVER_MAX_LOCK_MEM
ulimit -s $PLEX_MEDIA_SERVER_MAX_STACK_SIZE
ulimit -n $PLEX_MEDIA_SERVER_MAX_OPEN_FILES
 
CentOS7/SuSE/Ubuntu 15.04 Config:
 
To change the startup configuration and context of the systemd service edit the systemd service file: /lib/systemd/system/plexmediaserver.service.
 
On Ubuntu this file is located in: /etc/systemd/system/plexmediaserver.service
 
For changeing where Plex Media Server places its metadata files change the Environment setting for PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR in the plexmediaserver.service file.
You can edit the path within the quotationmarks to any directory of your choice. The path you put in there has one requirement. That you ensure that the user you run Plex Media Server as owns it. Default is the user plex. The directory you define has to exisit eg /opt/plex/Library/Application Support” has to be in place and owned by plex. Remember to chown plex on the dir you choose.
For changing the usercontext under which Plex Media Server runs as change the variables User and Group in the service file. When changing the user and group remember to change the ownership of your Plex Media Server’s Application Support Dir. So as an example if you are changing from the user plex to user awesomeuser then remember to run: chown -R awesomeuser /var/lib/plexmediaserver
After you have made your changes its important that you refresh the systemd subsystem. Run this command to let your changes take effect on the next restart/boot.

sudo systemctl --system daemon-reload

followed by

sudo service plexmediaserver start

to restart the service.

A note to users running systemd. If the group that is defined in the service file is not present startup will fail. This has been seen in cases where a user upgraded from an old rpm using systemd to a newer version (on SUSE 12.2 only). To fix this run: sudo groupadd plex
The original service file looks like 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
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 '/usr/lib/plexmediaserver/Plex\ Media\ Server'
Type=simple
User=plex
Group=plex
 
[Install]
WantedBy=multi-user.target