Jump to content


Photo

Clean systemd Scripts for Fedora 17


  • Please log in to reply
53 replies to this topic

#1 leonsio

leonsio

    Member

  • Members
  • PipPip
  • 77 posts

Posted 28 June 2012 - 09:10 AM

See posts below for updated version


Hello

i have changed/replaced the default init scripts (in RPM) with systemd one

if anyone interested in here they are:

1. Cleanup /etc/sysconfig/PlexMediaServer (remove ulimit code)

# Plex Media Server Config file.

# Set home of Plex Media Server 
PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver

# Set home for Plex metadata
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="$(echo ~plex)/Library/Application Support"

# the number of plugins that can run at the same time
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6

# where the mediaserver should store the transcodes
PLEX_MEDIA_SERVER_TMPDIR=/tmp

export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}"
export PLEX_MEDIA_SERVER_USER=$PLEX_MEDIA_SERVER_USER
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"

2. Modify /lib/systemd/system/plex.service

[Unit]
Description=Plex Media Server for Linux
After=network.target

[Service]
EnvironmentFile=-/etc/sysconfig/PlexMediaServer
ExecStart=/usr/lib/plexmediaserver/start.sh
KillMode=process
Type=forking
User=plex

[Install]
WantedBy=multi-user.target

reload systemd after changes with: systemctl daemon-reload

3. Create "limit" file for plex user

vi /etc/security/limits.d/plex.conf

plex	soft 	stack		10000
plex	soft	nofile		4096
plex	hard 	memlock		3000
plex	soft 	memlock		3000

4. Modify start.sh in plexmediaserver directory

vi /usr/lib/plexmediaserver/start.sh

#!/bin/sh
# Source Plex Variables
[ -r /etc/sysconfig/PlexMediaServer ] && . /etc/sysconfig/PlexMediaServer
/usr/lib/plexmediaserver/Plex\ Media\ Server &


Now you have a clean configuration with systemd, you can remove the old init file in /etc/init.d/

Start:

service plex start ( or systemctl start plex.service )

Stop

service plex stop ( or systemctl stop plex.service )

#2 b0rken

b0rken

    Newbie

  • Members
  • Pip
  • 7 posts
  • Location: San Diego, CA.

Posted 28 June 2012 - 03:57 PM

I was working on something similar over the last couple of days actually... but you beat me to it.

Thanks!


Hello

i have changed/replaced the default init scripts (in RPM) with systemd one

if anyone interested in here they are:

1. Cleanup /etc/sysconfig/PlexMediaServer (remove ulimit code)

# Plex Media Server Config file.

# Set home of Plex Media Server 
PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver

# Set home for Plex metadata
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="$(echo ~plex)/Library/Application Support"

# the number of plugins that can run at the same time
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6

# where the mediaserver should store the transcodes
PLEX_MEDIA_SERVER_TMPDIR=/tmp

export LD_LIBRARY_PATH="${PLEX_MEDIA_SERVER_HOME}"
export PLEX_MEDIA_SERVER_USER=$PLEX_MEDIA_SERVER_USER
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"

2. Modify /lib/systemd/system/plex.service

[Unit]
Description=Plex Media Server for Linux
After=network.target

[Service]
EnvironmentFile=-/etc/sysconfig/PlexMediaServer
ExecStart=/usr/lib/plexmediaserver/start.sh
KillMode=process
Type=forking
User=plex

[Install]
WantedBy=multi-user.target

reload systemd after changes with: systemctl daemon-reload

3. Create "limit" file for plex user

vi /etc/security/limits.d/plex.conf

plex	soft 	stack		10000
plex	soft	nofile		4096
plex	hard 	memlock		3000
plex	soft 	memlock		3000

4. Modify start.sh in plexmediaserver directory

vi /usr/lib/plexmediaserver/start.sh

#!/bin/sh
# Source Plex Variables
[ -r /etc/sysconfig/PlexMediaServer ] && . /etc/sysconfig/PlexMediaServer
/usr/lib/plexmediaserver/Plex\ Media\ Server &


Now you have a clean configuration with systemd, you can remove the old init file in /etc/init.d/

Start:

service plex start ( or systemctl start plex.service )

Stop

service plex stop ( or systemctl stop plex.service )



#3 Mark Walker

Mark Walker

    HACK THE PLANET!

  • Plex Ninja
  • PipPipPipPipPipPip
  • 1941 posts
  • Location: Aarhus - Denmark

Posted 28 June 2012 - 04:57 PM

I hear you guys :D

It's been on my mind ever since I did the rpm's and added fedora 16+ support.

Though I agree that this approach is cleaner, I also want to keep compatibility with other rpm based OS's. Also the current configuration keeps all plex settings in one file, which simplifies configuration.

So if you have any ideas on how to keep the current config, and add the plex systemd service in some way to support this, I'm all ears.

It's easier for us to maintain and support one rpm, rather than multiple versions based on OS flavors.

/Mark
Get you Plex guides here: Naming Guide, NAS Guide, NTFS on Linux Guide, Linux Permissions Guide, Logs & Library Maintenance Help, Plex Help Page.

My Plex world:
Primary PMS: NAS - 24 bay Inter-Tech 4324L, Xeon E3-1230v2, SuperMicro X9SCM-F, 60GB Vertex SSD, 7x1.5TB SATA Drives
Channel PMS/HTPC/EyeTV: Mid 2011 Mac Mini 4GB RAM 60GB Vertex SSD, 50" Kuro
Clients: Hackintosh - Xeon E3-1275v2, 27" CinemaDisplay, 2010 15" MBP, ATV2, Roku3, iPhone 3gs 32GB, iPhone 5 64GB, iPad 3 16GB

#4 leonsio

leonsio

    Member

  • Members
  • PipPip
  • 77 posts

Posted 29 June 2012 - 08:33 AM

Hello Mark

here the ultimative startup construct with systemd ^^

1. /etc/sysconfig/PlexMediaServer

# Plex Media Server Config file.

# Set home for Plex metadata (change if needed)
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/var/lib/plexmediaserver/Library/Application Support"

# the number of plugins that can run at the same time
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6

# where the mediaserver should store the transcodes
PLEX_MEDIA_SERVER_TMPDIR=/tmp


description: only this options will be changed, or should be changed by "normal" users, primary the PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR option

2. /lib/systemd/system/plex.service

[Unit]
Description=Plex Media Server for Linux
After=network.target

[Service]
EnvironmentFile=-/etc/sysconfig/PlexMediaServer
ExecStart=/usr/lib/plexmediaserver/start.sh
KillMode=process
Type=forking
User=plex

[Install]
WantedBy=multi-user.target

Description: Environment variables will be loaded from /etc/sysconfig/PlexMediaServer and are automaticale passed to Plex
all processes are running with user "plex"


3. /etc/security/limits.d/plex.conf

plex	soft 	stack		10000
plex	soft	nofile		4096
plex	hard 	memlock		3000
plex	soft 	memlock		3000

Description: This settings should only be changed by "expert" user
this file is needed, because ALL processes are running with user plex, which has normlay no rights to change ulimit flags == you can not use this in startup files

4. /usr/lib/plexmediaserver/start.sh


#!/bin/sh
# Source Plex Variables
SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname ${SCRIPT}`
export LD_LIBRARY_PATH="${SCRIPTPATH}"
export PLEX_MEDIA_SERVER_HOME="${SCRIPTPATH}"
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"
/usr/lib/plexmediaserver/Plex\ Media\ Server &

Description: this file only sets the LD_LIBRARY_PATH parameter and start Plex Media Server as child process
---------------------------------

To the last step:

1. it is possible to add the lib path in form of a /etc/ld.so.conf.d/plex.conf file
2. we are on linux, it should be possible to build PMS with shared library support, i mean with shared system libs

Example: why should PMS package use own libssl.so then fedora already have one if user have installed openssl ???

#5 leonsio

leonsio

    Member

  • Members
  • PipPip
  • 77 posts

Posted 29 June 2012 - 08:57 AM

@Marc

you can distribute the /lib/systemd/system/plex.service and the old /etc/init.d/plexmediaserver together in one RPM and the check if systemd is present, then use only the plex.service file
create new directory in the rpm like: /usr/share/plexmediaserver and put both scripts in it. In the postinstall script try to detect the distribution version

cat /etc/fedora-release | cut -d" " -f3

or try to check if systemd is installed

rpm -qa | grep systemd ; echo $?

then put the init or systemd script on the right place and dont forget to add a postinstall script to remove the files after deinstallation



splitting the config files in /etc/sysconfig & /etc/security/limits.d is supported by all distributions ;)



the only "problem" is, that systemd does not support any scripts in the EnviromentFile, i think it is not a big problem, beause your are adding a plex user with own home/lib directory so thy are you trying to script the path to the Library??

start.sh file can be used by bouth scripts init/systemd

#6 Mark Walker

Mark Walker

    HACK THE PLANET!

  • Plex Ninja
  • PipPipPipPipPipPip
  • 1941 posts
  • Location: Aarhus - Denmark

Posted 29 June 2012 - 11:26 AM

So many thoughts :D So many roads to go down :D

I keep rethinking different ways of doing it.

I think I'll have to explain my thoughts in sections :D

Section 1: The /etc/sysconfig/PlexMediaServer file.

The reason for putting it all there, is as said before centralizing it and have an easy way of changing ulimit option no matter what rpm OS flavor you run it on. Though for ulimit options to work, it requires root to set them first, or have the /etc/security/limits.d/plex.conf in place with at least the same values as the config file. But there is no harm having these options and the plex.conf file in /etc/security/limits.d dir, to support both CentOS/ClearOS and Fedora 16+ at the same time.

Section 2: The /etc/init.d/plexmediaserver script.

As not all systems have systemd starting plex via this script works well. It starts plex in the context of user plex, and it creates pid and lock file for system v based systems to recognize if plex is running or not. So besides SUSE this works perfectly. BUT not an optimal solution for systemd based OS's.

Section 3: Systemd and /lib/systemd/system/plex.service

This is where I want to improve things. I believe that an option could be to add the /etc/security/limits.d/plex.conf file and modify /lib/systemd/system/plex.service in accordance to leonsio's recomendations. Today the RPM allready does a fedora 16+ check on install, so it should work out of the box. The code used for install via the rpm is this:

# Check if release is systemd based and add plex service accordingly.
if [[ ! $(cat /etc/redhat-release) =~ (^Fedora).*?1[5-9].*$ ]]; then
    chkconfig --add plexmediaserver
else
    systemctl daemon-reload
    systemctl enable plex.service
fi

And having the plex.service file to be as leonsio described it should just work. I have not tested this, and won't have time until next week. But for my brain today, it seems as an ideal solution. So on systemd systems, even though the /etc/init.d script is there, it won't be used (but can, if users prefer).

Does this sound nuts? Or would that suit both worlds?

/Mark

P.S. How does systemd kill of plex when run from that start.sh script in /usr/lib/plexmediaserver?

P.P.S. in regards to LD_LIBRARY_PATH, here is a warning. DO NOT PUT /usr/lib/plexmediaserver IN ld.so.conf. PLEX USES MODIFIED VERSIONS OF THE BINARIES THAT MIGHT BREAK STUFF. Which also explains why stuff isn't dynamically linked :D
Get you Plex guides here: Naming Guide, NAS Guide, NTFS on Linux Guide, Linux Permissions Guide, Logs & Library Maintenance Help, Plex Help Page.

My Plex world:
Primary PMS: NAS - 24 bay Inter-Tech 4324L, Xeon E3-1230v2, SuperMicro X9SCM-F, 60GB Vertex SSD, 7x1.5TB SATA Drives
Channel PMS/HTPC/EyeTV: Mid 2011 Mac Mini 4GB RAM 60GB Vertex SSD, 50" Kuro
Clients: Hackintosh - Xeon E3-1275v2, 27" CinemaDisplay, 2010 15" MBP, ATV2, Roku3, iPhone 3gs 32GB, iPhone 5 64GB, iPad 3 16GB

#7 leonsio

leonsio

    Member

  • Members
  • PipPip
  • 77 posts

Posted 29 June 2012 - 12:20 PM

P.S. How does systemd kill of plex when run from that start.sh script in /usr/lib/plexmediaserver?


systemd looks for all forks/childs a save this data

example:

# service plex status
Redirecting to /bin/systemctl  status plex.service
plex.service - Plex Media Server for Linux
	  Loaded: loaded (/usr/lib/systemd/system/plex.service; enabled)
	  Active: active (running) since Fri, 29 Jun 2012 13:09:58 +0200; 1h 9min ago
	 Process: 29804 ExecStart=/usr/lib/plexmediaserver/start.sh (code=exited, status=0/SUCCESS)
	Main PID: 29807 (Plex Media Serv)
	  CGroup: name=systemd:/system/plex.service
		  ├ 29807 /usr/lib/plexmediaserver/Plex Media Server
		  ├ 29839 Plex Plug-in [com.plexapp.system] /mnt/daten/Server/Plex/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Co...
		  ├ 29875 /usr/lib/plexmediaserver/Plex DLNA Server
		  ├ 31698 Plex Plug-in [com.plexapp.agents.thetvdb] /mnt/daten/Server/Plex/Library/Application Support/Plex Media Server/Plug-ins/Framework.b...
		  ├ 31732 Plex Plug-in [com.plexapp.agents.localmedia] /mnt/daten/Server/Plex/Library/Application Support/Plex Media Server/Plug-ins/Framewor...
		  └ 31839 /usr/lib/plexmediaserver/Plex Media Scanner --scan --refresh --section 8

look at the process side:

# pstree
systemd─┬─NetworkManager─┬─dhclient
        │                └─3*[{NetworkManager}]
        ├─Plex Media Serv─┬─Plex DLNA Serve───18*[{Plex DLNA Serve}]
        │                 ├─Plex Media Scan───3*[{Plex Media Scan}]
        │                 ├─python───12*[{python}]
        │                 ├─python───33*[{python}]
        │                 ├─python───9*[{python}]
        │                 └─37*[{Plex Media Serv}]


[14:22:32][root@MediaStore:~]
# ps aux | grep -i plex | grep -v grep
plex     29807  0.6  2.5 1082260 53128 ?       Sl   13:09   0:26 /usr/lib/plexmediaserver/Plex Media Server
plex     29839  0.7  3.7 935608 76892 ?        SNl  13:09   0:32 Plex Plug-in [com.plexapp.system] /mnt/daten/Server/Plex/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py --server-version 0.9.6.4.154-c16a2c6 /mnt/daten/Server/Plex/Library/Application Support/Plex Media Server/Plug-ins/System.bundle
plex     29875  0.2  0.9 923604 19548 ?        Sl   13:10   0:09 /usr/lib/plexmediaserver/Plex DLNA Server
plex     31698  1.4  2.0 1055920 42780 ?       Sl   14:10   0:11 Plex Plug-in [com.plexapp.agents.thetvdb] /mnt/daten/Server/Plex/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py --server-version 0.9.6.4.154-c16a2c6 /mnt/daten/Server/Plex/Library/Application Support/Plex Media Server/Plug-ins/TheTVDB.bundle
plex     31732  0.5  1.9 869464 40800 ?        Sl   14:10   0:03 Plex Plug-in [com.plexapp.agents.localmedia] /mnt/daten/Server/Plex/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py --server-version 0.9.6.4.154-c16a2c6 /mnt/daten/Server/Plex/Library/Application Support/Plex Media Server/Plug-ins/LocalMedia.bundle
plex     31839 10.7  1.2 446136 26172 ?        Sl   14:11   1:07 /usr/lib/plexmediaserver/Plex Media Scanner --scan --refresh --section 8


it kill the start.sh script and all childs/forks of it

#8 Mark Walker

Mark Walker

    HACK THE PLANET!

  • Plex Ninja
  • PipPipPipPipPipPip
  • 1941 posts
  • Location: Aarhus - Denmark

Posted 29 June 2012 - 12:29 PM

Log story short :D

cgroups :D That was the answer I was looking for :D

Introduced in Redhat 6, and started in F15 :D

Thanks for that info.

Getting back on track. Any input on my thoughts?

/Mark
Get you Plex guides here: Naming Guide, NAS Guide, NTFS on Linux Guide, Linux Permissions Guide, Logs & Library Maintenance Help, Plex Help Page.

My Plex world:
Primary PMS: NAS - 24 bay Inter-Tech 4324L, Xeon E3-1230v2, SuperMicro X9SCM-F, 60GB Vertex SSD, 7x1.5TB SATA Drives
Channel PMS/HTPC/EyeTV: Mid 2011 Mac Mini 4GB RAM 60GB Vertex SSD, 50" Kuro
Clients: Hackintosh - Xeon E3-1275v2, 27" CinemaDisplay, 2010 15" MBP, ATV2, Roku3, iPhone 3gs 32GB, iPhone 5 64GB, iPad 3 16GB

#9 leonsio

leonsio

    Member

  • Members
  • PipPip
  • 77 posts

Posted 29 June 2012 - 12:37 PM

i will not recommend you to mix init scripts with systemd
if you do this, set then different names

mixing this scripts can lead to problems

example:

anyone try to start plex with systemd and stop it with init script, or inversely.....

look at my #5 post, create /usr/share/plexmediaserver/ folder with bouth of the scripts and then decide on the release version which script should be installed
P.S. you are creating a rpm for suse to, you can use the systemd script without any changes on it

P.P.S. i know that PMS use modified libs. But I think that we should eliminate it with the time ;) Alternatively, you can bind the entire application statically and use it without any "modification" on all distributions *g*

#10 Mark Walker

Mark Walker

    HACK THE PLANET!

  • Plex Ninja
  • PipPipPipPipPipPip
  • 1941 posts
  • Location: Aarhus - Denmark

Posted 29 June 2012 - 12:56 PM

i will not recommend you to mix init scripts with systemd
if you do this, set then different names

mixing this scripts can lead to problems

example:

anyone try to start plex with systemd and stop it with init script, or inversely.....

look at my #5 post, create /usr/share/plexmediaserver/ folder with bouth of the scripts and then decide on the release version which script should be installed
P.S. you are creating a rpm for suse to, you can use the systemd script without any changes on it

P.P.S. i know that PMS use modified libs. But I think that we should eliminate it with the time ;) Alternatively, you can bind the entire application statically and use it without any "modification" on all distributions *g*



No plan on mixing it, just having them both in the same rpm. So for systemd it would use /usr/lib/plexmediaserver/start.sh and for system v systems, run /etc/init.d/plexmediaserver. That way we keep the init scripts seperated, and can keep it to one rpm.

SUSE: Yeah, I'll look at that later on :D Still many fun things to do. And get it working on these platforms first. The init script required reworking for it to work on SUSE.

Thanks for feed back. Giving me many thoughts.

/Mark
Get you Plex guides here: Naming Guide, NAS Guide, NTFS on Linux Guide, Linux Permissions Guide, Logs & Library Maintenance Help, Plex Help Page.

My Plex world:
Primary PMS: NAS - 24 bay Inter-Tech 4324L, Xeon E3-1230v2, SuperMicro X9SCM-F, 60GB Vertex SSD, 7x1.5TB SATA Drives
Channel PMS/HTPC/EyeTV: Mid 2011 Mac Mini 4GB RAM 60GB Vertex SSD, 50" Kuro
Clients: Hackintosh - Xeon E3-1275v2, 27" CinemaDisplay, 2010 15" MBP, ATV2, Roku3, iPhone 3gs 32GB, iPhone 5 64GB, iPad 3 16GB

#11 leonsio

leonsio

    Member

  • Members
  • PipPip
  • 77 posts

Posted 29 June 2012 - 01:16 PM

next suse version (12.2) will have systemd too ;)

note you can not use any script in /etc/sysconfig/PlexMediaServer file if it should work with systemd

you can try to modify the init script to work with start.sh too, or has sysv problems with it?

#12 Mark Walker

Mark Walker

    HACK THE PLANET!

  • Plex Ninja
  • PipPipPipPipPipPip
  • 1941 posts
  • Location: Aarhus - Denmark

Posted 29 June 2012 - 01:53 PM

Noted, then I'll have to setup rpm behavior in regards to that os too.. Darn it :D

This is just an environment file /etc/sysconfig/PlexMediaServer. Should provide any issues on systemd. (maybe you are referring to the ulimit stuff?)

No there should be no problem in using that script. Just as long as the surrounding stuff gets done (lockfile/pidfile/startup/shutdown checks).I would rather split it up into two. One for system v and one where systemd calls Tobias's job. Since Tobias allways adds the start.sh script, I can just piggyback on that.

/Mark
Get you Plex guides here: Naming Guide, NAS Guide, NTFS on Linux Guide, Linux Permissions Guide, Logs & Library Maintenance Help, Plex Help Page.

My Plex world:
Primary PMS: NAS - 24 bay Inter-Tech 4324L, Xeon E3-1230v2, SuperMicro X9SCM-F, 60GB Vertex SSD, 7x1.5TB SATA Drives
Channel PMS/HTPC/EyeTV: Mid 2011 Mac Mini 4GB RAM 60GB Vertex SSD, 50" Kuro
Clients: Hackintosh - Xeon E3-1275v2, 27" CinemaDisplay, 2010 15" MBP, ATV2, Roku3, iPhone 3gs 32GB, iPhone 5 64GB, iPad 3 16GB

#13 angela_bot

angela_bot

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 03 July 2012 - 02:52 PM

The current version of suse already has support for systemd. I'm using it on 12.1 with my own plex.service file, which is slightly different from leonsio's and doesn't require a separate bash script.

/lib/systemd/system/plex.service:

[Unit]
Description=Plex Media Server for Linux
After=network.target

[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/plex
ExecStartPre=/usr/bin/sh -c "ulimit -s $PLEX_MEDIA_SERVER_MAX_STACK_SIZE"
ExecStartPre=/usr/bin/sh -c "ulimit -n $PLEX_MEDIA_SERVER_MAX_OPEN_FILES"
ExecStart=/usr/lib/plexmediaserver/PlexMediaServer
WorkingDirectory=/usr/lib/plexmediaserver
KillSignal=SIGQUIT
User=plex
Group=plex

[Install]
WantedBy=multi-user.target

/usr/lib/plexmediaserver/PlexMediaServer is a soft link to /usr/lib/plexmediaserver/Plex Media Server.


/etc/sysconfig/plex:

PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/home/plex/Library/Application Support
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
PLEX_MEDIA_SERVER_MAX_STACK_SIZE=10000
PLEX_MEDIA_SERVER_MAX_LOCK_MEM=3000
PLEX_MEDIA_SERVER_MAX_OPEN_FILES=4096
PLEX_MEDIA_SERVER_TMPDIR=/tmp
LD_LIBRARY_PATH=/usr/lib/plexmediaserver
TMPDIR=/tmp
LC_ALL="en_US.UTF-8"
LANG="en_US.UTF-8"


#14 Mark Walker

Mark Walker

    HACK THE PLANET!

  • Plex Ninja
  • PipPipPipPipPipPip
  • 1941 posts
  • Location: Aarhus - Denmark

Posted 03 July 2012 - 05:22 PM

The current version of suse already has support for systemd. I'm using it on 12.1 with my own plex.service file, which is slightly different from leonsio's and doesn't require a separate bash script.

/lib/systemd/system/plex.service:

[Unit]
Description=Plex Media Server for Linux
After=network.target

[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/plex
ExecStartPre=/usr/bin/sh -c "ulimit -s $PLEX_MEDIA_SERVER_MAX_STACK_SIZE"
ExecStartPre=/usr/bin/sh -c "ulimit -n $PLEX_MEDIA_SERVER_MAX_OPEN_FILES"
ExecStart=/usr/lib/plexmediaserver/PlexMediaServer
WorkingDirectory=/usr/lib/plexmediaserver
KillSignal=SIGQUIT
User=plex
Group=plex

[Install]
WantedBy=multi-user.target

/usr/lib/plexmediaserver/PlexMediaServer is a soft link to /usr/lib/plexmediaserver/Plex Media Server.


/etc/sysconfig/plex:

PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/home/plex/Library/Application Support
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
PLEX_MEDIA_SERVER_MAX_STACK_SIZE=10000
PLEX_MEDIA_SERVER_MAX_LOCK_MEM=3000
PLEX_MEDIA_SERVER_MAX_OPEN_FILES=4096
PLEX_MEDIA_SERVER_TMPDIR=/tmp
LD_LIBRARY_PATH=/usr/lib/plexmediaserver
TMPDIR=/tmp
LC_ALL="en_US.UTF-8"
LANG="en_US.UTF-8"


Very nice solution. I like it. Am gonna use some of this to bash at fedora 17, too see how it can fits into the current setup. We had to add a if plex support dir dos not exist create clause to the unit script, to fix a bug. So need to work that in there ;)

Thanks for posting this.

/Mark
Get you Plex guides here: Naming Guide, NAS Guide, NTFS on Linux Guide, Linux Permissions Guide, Logs & Library Maintenance Help, Plex Help Page.

My Plex world:
Primary PMS: NAS - 24 bay Inter-Tech 4324L, Xeon E3-1230v2, SuperMicro X9SCM-F, 60GB Vertex SSD, 7x1.5TB SATA Drives
Channel PMS/HTPC/EyeTV: Mid 2011 Mac Mini 4GB RAM 60GB Vertex SSD, 50" Kuro
Clients: Hackintosh - Xeon E3-1275v2, 27" CinemaDisplay, 2010 15" MBP, ATV2, Roku3, iPhone 3gs 32GB, iPhone 5 64GB, iPad 3 16GB

#15 leonsio

leonsio

    Member

  • Members
  • PipPip
  • 77 posts

Posted 05 July 2012 - 08:47 AM

nice job @angela_bot

it has some pro/contra arguments for splitting/centralization of the config files

i think the most users dont know that whey do, if they make changes on ulimit/ld_path variables this changes can destabilize the complete system
this was my reason to split the config in different files ;)

@ZiGGiMoN have you already included the systemd changes in the actual 0.9.6.5 rpm?

#16 Mark Walker

Mark Walker

    HACK THE PLANET!

  • Plex Ninja
  • PipPipPipPipPipPip
  • 1941 posts
  • Location: Aarhus - Denmark

Posted 05 July 2012 - 10:40 AM

nice job @angela_bot

it has some pro/contra arguments for splitting/centralization of the config files

i think the most users dont know that whey do, if they make changes on ulimit/ld_path variables this changes can destabilize the complete system
this was my reason to split the config in different files ;)

@ZiGGiMoN have you already included the systemd changes in the actual 0.9.6.5 rpm?


0.9.6.5 GM release came sneaking up behind me :D So I didn't get it wrapped up before this. And then angela_bot came up with this slightly different approach which made me think. I'm hoping to have it done by 0.9.6.6. But as you prob will have noticed in the init script of 0.9.6.5, we now have a test section in the startup script that tests if the Application Support dir is created. I'll need to work that into the service as well.

Was thinking this:

ExecStartPre=su -s /bin/sh $PLEX_USER -c "mkdir -p '${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}' > /dev/null 2>&1 ; if [ ! $? -eq 0 ]; then; echo \"WARNING COULDN'T CREATE '${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}', MAKE SURE I HAVE PERMISSON TO DO THAT!'; exit 1; fi"

But will have to test things first.

And yes those values can be tampered with, but I would also expect that users that tamper with the config file also would know what they are doing, since its not a file normally referred to in threads, nor support issues. This is my assumption anyway :D Splitting it out would require me to maintain two files for the same option in one rpm. So if I can keep it in one, I'll try to.

- Heres to hoping I get it done for 0.9.6.6 :D

In the spirit of Elan and Tobias. There is no ETA :D

/Mark
Get you Plex guides here: Naming Guide, NAS Guide, NTFS on Linux Guide, Linux Permissions Guide, Logs & Library Maintenance Help, Plex Help Page.

My Plex world:
Primary PMS: NAS - 24 bay Inter-Tech 4324L, Xeon E3-1230v2, SuperMicro X9SCM-F, 60GB Vertex SSD, 7x1.5TB SATA Drives
Channel PMS/HTPC/EyeTV: Mid 2011 Mac Mini 4GB RAM 60GB Vertex SSD, 50" Kuro
Clients: Hackintosh - Xeon E3-1275v2, 27" CinemaDisplay, 2010 15" MBP, ATV2, Roku3, iPhone 3gs 32GB, iPhone 5 64GB, iPad 3 16GB

#17 ItsTheSource

ItsTheSource

    Dedicated Member

  • Members
  • PipPipPip
  • 112 posts
  • Location: Richmond, VA

Posted 12 July 2012 - 05:29 AM

Hmm...intriguing :D. Don't forget that PMS can be run as any user now though. The service file should source the configuration file for the user & if it can't handle that then it's kinda pointless to abandon the bash script. If the service file can handle a variable for user then I think you should ditch the creation of the user 'plex' during setup & create it upon startup. If a user wants to run PMS as another user, it's kinda pointless to create the user 'plex' isn't it?

This adds a little more flexibility to the angela_bot's script...
[Unit]
Description=Plex Media Server for Linux
After=network.target

[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/plex
ExecStartPre=<if user does not exist, create $PLEX_MEDIA_SERVER_USER>
ExecStartPre=/usr/bin/sh -c "ulimit -s $PLEX_MEDIA_SERVER_MAX_STACK_SIZE"
ExecStartPre=/usr/bin/sh -c "ulimit -n $PLEX_MEDIA_SERVER_MAX_OPEN_FILES"
ExecStart=/usr/lib/plexmediaserver/PlexMediaServer
WorkingDirectory=/usr/lib/plexmediaserver
KillSignal=SIGQUIT
User=$PLEX_MEDIA_SERVER_USER
Group=$PLEX_MEDIA_SERVER_USER

[Install]
WantedBy=multi-user.target

Moving my library off my / partition & to my /home partition. I'll have to change the startup user so PMS has access to its library, so I guess I'll be the guinea pig.

Edit: It doesn't seem to work with variables

Server: i5 3470/32GB DDR3/28TB ZFS Pool/FreeBSD 9.2 x64
Android Clients: Galaxy Nexus/Nexus 7
PC Clients:  Ubuntu Minimal 13.04


#18 Mark Walker

Mark Walker

    HACK THE PLANET!

  • Plex Ninja
  • PipPipPipPipPipPip
  • 1941 posts
  • Location: Aarhus - Denmark

Posted 12 July 2012 - 11:30 AM

Hmm.. this does not appear to be a trivial task :D

Without the ability to set variables in the service file, it will not be able to dynamically handle user change or support dir change. Also when trying to add the creation of the support directory if not existent proves to be a challenge.

The easy way out, would be to call a scripts externally. But would not be a sleek :D Also it would not solve the issue of having plex locked in at one user (plex).

If anyone has a superb way of adding scripts/tests inline in ExectStartPre= I'm all ears :D Otherwise I'll have to consider adding a script in /usr/lib/plexmediaserver for the systemd setup to call. So far my tests haven't provided a solution.

/Mark
Get you Plex guides here: Naming Guide, NAS Guide, NTFS on Linux Guide, Linux Permissions Guide, Logs & Library Maintenance Help, Plex Help Page.

My Plex world:
Primary PMS: NAS - 24 bay Inter-Tech 4324L, Xeon E3-1230v2, SuperMicro X9SCM-F, 60GB Vertex SSD, 7x1.5TB SATA Drives
Channel PMS/HTPC/EyeTV: Mid 2011 Mac Mini 4GB RAM 60GB Vertex SSD, 50" Kuro
Clients: Hackintosh - Xeon E3-1275v2, 27" CinemaDisplay, 2010 15" MBP, ATV2, Roku3, iPhone 3gs 32GB, iPhone 5 64GB, iPad 3 16GB

#19 ItsTheSource

ItsTheSource

    Dedicated Member

  • Members
  • PipPipPip
  • 112 posts
  • Location: Richmond, VA

Posted 12 July 2012 - 11:25 PM

What about this?

ExecStartPre=/usr/bin/test -d "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR" || mkdir -p "$PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR"

And if that works, you could use grep to search /etc/passwd for users & add them if they're not present.

ExecStartPre=/bin/grep "^<username>" > /dev/null || /usr/sbin/useradd ...

Server: i5 3470/32GB DDR3/28TB ZFS Pool/FreeBSD 9.2 x64
Android Clients: Galaxy Nexus/Nexus 7
PC Clients:  Ubuntu Minimal 13.04


#20 xwaver

xwaver

    Member

  • Members
  • PipPip
  • 28 posts

Posted 05 August 2012 - 02:35 AM

Hmm.. this does not appear to be a trivial task :D

Without the ability to set variables in the service file, it will not be able to dynamically handle user change or support dir change. Also when trying to add the creation of the support directory if not existent proves to be a challenge.

The easy way out, would be to call a scripts externally. But would not be a sleek :D Also it would not solve the issue of having plex locked in at one user (plex).

If anyone has a superb way of adding scripts/tests inline in ExectStartPre= I'm all ears :D Otherwise I'll have to consider adding a script in /usr/lib/plexmediaserver for the systemd setup to call. So far my tests haven't provided a solution.

/Mark


Well, you could try leveraging the .wants system in systemd to do prerequisite checks and executions for tests. And unless I'm mistaken, these are standard expansions to solve the multi-user issue.
"%u User name This is the name of the configured user of the unit, or (if none is set) the user running the systemd instance."
"%h User home directory This is the home directory of the configured user of the unit, or (if none is set) the user running the systemd instance."




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users