Author Topic: [HOWTO] Plex Media Server  (Read 10777 times)

FastLaneJB

  • Zen Apprentice
  • *
  • Posts: 20
  • Karma: +0/-0
    • View Profile
[HOWTO] Plex Media Server
« on: December 11, 2013, 03:34:52 pm »
Hi,

OK, I've worked out a way of running Plex Media Server as the user plex and having access to Samba shares configured in Zentyal so I thought I would share. This is the best way I've come up with doing this but let us know if you can think of a better way, it's been working fine for me for quite a few weeks now.

I'm not a fan of having my services running as root, my initial attempt at this had it running as a user I made inside Zentyal's LDAP with pam enabled however the service would fail on occasions when other services were restarted on Zentyal (At a guess, Samba and LDAP). So when it was up and running it worked fine but it wasn't reliable.

Anyway here we go. I'm assuming you've got some basic Linux knowledge but you shouldn't need much. I'm assuming you've got a share setup in Zentyal already with some media in it but if not make a blank one ready to have media in it.

Connect onto your Zentyal server's command line. I'm using Putty but connect on how you please.

First I switch to root so I don't need to type sudo infront of every command. Enter your password and you should now be root.

Code: [Select]
sudo -i
Lets get right to it and get Plex downloaded and installed. The commands below will download and install the 64bit version, go to the Plex site and get the URL of the 32bit one if your Zentyal isn't 64bit. This is the current version at the time of writing but again you might want to check.

I like to store the installer in /usr/src so I know which version is loaded. Maybe not the right place to put it but it's what I do.

Code: [Select]
mkdir /usr/src/plex
cd /usr/src/plex
wget http://downloads.plexapp.com/plex-media-server/0.9.8.14.263-139ddbc/plexmediaserver_0.9.8.14.263-139ddbc_amd64.deb
dpkg -i plexmediaserver_0.9.8.14.263-139ddbc_amd64.deb

Right that should have Plex installed and running under it's own plex system account.

Now we need to modify the way Zentyal's Samba works with permissions. This didn't work on early versions of Zentyal's 3.2 Samba module because of a bug but it's working on newer versions. So if your on a fresh 3.2 install you should update first.

I'm a nano person but use which ever editor you like.

Code: [Select]
nano /etc/zentyal/samba.conf
Change the following line so it's not commented out and is enabled with a yes.

Code: [Select]
unmanaged_acls = yes
Lets restart the service so this takes affect.

Code: [Select]
/etc/init.d/zentyal samba restart
Now we need to fix the permissions on the folder. I'm using hooks for this so they are checked and fixed if Zentyal overwrites them at any point.

I'm using acl files as I have more than just plex needing permission to the folders and it makes it easier to manage.

Code: [Select]
nano /etc/zentyal/hooks/base.acl
Add in the following line.

Code: [Select]
user:plex:rx
This is used to set permissions to the /home/samba and /home/samba/shares folders. Now I have another acl which is used for the media folder. I give Plex write permission because you can allow Plex to delete media from a device if you want, you can give it read only access if you want. If you want read only take the w out.

Code: [Select]
nano /etc/zentyal/hooks/media.acl
Add in the following lines.

Code: [Select]
user:plex:rwx
default:user:plex:rwx

If you've already got a samba.postservice then add this code to it, if not make a new file for it.

Code: [Select]
nano /etc/zentyal/hooks/samba.postservice
Add the following code but modify the path to match where your share is. I'm assuming it's in /home/samba/shares default location but again if not just change this.

Code: [Select]
#!/bin/bash

# Modify permissions for base folders
setfacl -M /etc/zentyal/hooks/base.acl /home/samba
setfacl -M /etc/zentyal/hooks/base.acl /home/samba/shares

# Check for missing permissions on shares
if ! getfacl -p /home/samba/shares/media | grep -q "plex"
then
   setfacl -R -M /etc/zentyal/hooks/media.acl /home/samba/shares/media
fi

This should allow the plex system account to have access to your media files. Lets restart Samba so the permissions are updated.

Code: [Select]
/etc/init.d/zentyal samba restart
Now we just need to sort out the firewall. So log into the Zentyal Administration Interface. Go to Network and Services and click on Add New. I've got 2 services, one which is allowed from outside my network for MyPlex and another which is internal.

So lets make the internal / external ports first.

TCP 32400 (Plex Web Interface)
TCP 32433 (Plex HTTPS which at the time of writing isn't used but should be in the future).


Now make another Service which is what we need for uPnP inside your local network. Add in the following ports.

TCP 1662
TCP 32469
UDP 1900
UDP 5353
UDP 32410
UDP 32413


Now go to Firewall, Packet Filter and Configure Rules for "Filtering rules from internal networks to Zentyal". Add in both the internal and internal / external services you've setup as allow.

Now go to Firewall, Packet Filter and Configure Rules for "Filtering rules from external networks to Zentyal". Add in just the internal / external service which has the 2 ports in it.

Save changes so this change is enabled on the firewall.

Finally go to http://*zentyal-ip*:32400/web so you can configure Plex. When it comes to MyPlex you need you have Advanced Settings and then tell it to manually specify port which should be 32400. Otherwise it'll try and pick a Random port and not get through Zentyal.

You should be able to add in your media in your Samba share and that's it. Go fire up a Plex Client and give it a whirl.

Hope this helps out. I've got some other services running which I might document as well given some time.

Laurent Dinclaux

  • Zen Monk
  • **
  • Posts: 83
  • Karma: +5/-0
    • View Profile
    • Gecka
Re: [HOWTO] Plex Media Server
« Reply #1 on: January 07, 2014, 03:55:40 am »
Thanks for that guide but I am a bit concerned by some things, first, the "unmanaged_acls = yes". Why ? I don't want Samba to not manage the settings of all my shares. Aren't the script you wrote enough ?
Laurent