Plex Media Server on your NAS.

Plex Media Center bridges the gap between your NAS and your home theater, doing so with a visually appealing user interface that provides instant access to your media.

Moderator: Lillian.W@AST

MikeG.6.5
Posts: 917
youtube meble na wymiar Warszawa
Joined: Fri May 15, 2015 1:56 am

Plex Media Server on your NAS.

Post by MikeG.6.5 »

There have been a few posts lately all reporting issues with Plex Media Server and getting it running smoothly. As I frequent both this and Plex's forums and wind up helping a lot of people on either/both boards with a lion's share of the problems I'm going to offer some starting suggestions on how to make Plex run as smoothly as possible.

I started Plexing with a 202T which worked very well for almost a year. I converted all of my media to Plex Friendly containers and codecs to get it working well. I decided I wanted some more horsepower, so upgraded to a 7004T this spring. This is truly a nice machine after getting a lot of bugs worked out of the system.

So before someone says XYZ update "bricked" my Plex install, here are a few ways to start looking at what's really going on and help others help you.

Requirements:

To delve into this, there are things you are going to need. This section will cover them.

WinSCP: A shell client app that runs on Windows XP through Windows 10. This gives a file manger view as well as a terminal window to run apps on your NAS without the ADM overhead. Asustor doesn't include this as part of the software suite you get with the NAS. They don't feel you need access to the file system or the ability to run apps on your NAS without going through Asustor's App Central. This is such a basic and essential tool, it's almost criminal it's not included with the NAS on purchase.

Plex Media Server: You can get this from the Asustor App Central or download a more up to date version from Plex's website and manually install in App Central. Asustor has an approval process for any apps in App Central and it is notoriously slow on getting versions up to date. PMS updates regularly, so get familiar with doing a manual install through App Central. You are better served getting PMS from Plex's own site.

ffmpeg: Required only if you are running conversion scripts for your media. This converts the media from whatever file container or codec it is currently in, into one more Plex Friendly. Clinton Halls CP scripts use this as well, and the scripts I use are based on his.

Mapped Ports/Port Forwarding/Static IP: Forget about EZRouter. This is a method that router manufacturers use to allow people to run dedicated servers through their internet connection. It is buggy and fraught with problems. Troubleshooting a server issue starts and ends with static IP and port forwards. If you intend to run Plex remotely or share with people outside of your home you need a mapped port on the server side as well as port forwarding on your router for stable consistent connections.

PlexPy: (For historical tracking of watched media) PlexPy tracks who has watched what, when and how it was sent to them. Plex doesn't include this information, so the only way to track it is to actually have the browser open when someone is streaming something without PlexPy. To install this you also need to install Python from App Central.

File Locations:

Asustor puts it's installed apps and the log files for those apps in folders hidden from the ADM file manager. You can't even see log files without using WinSCP or something similar. These are the paths to the files you will need to either examine logs or back up history files:

Plex Media Server Logs: The log files are located here: /volume1/Plex/Library/Plex Media Server/Logs You cannot get to this with ADM's file manger and symlinking doesn't work. WinSCP is the only way to get to this folder. Generally, the only file needed for current sessions is this one: Plex Media Server.log. The other files have to do with things like deep scans, scan reports and limited historical. If you are like me, the DLNA logs will be zero byte files. (DLNA is problematic when your libraries start getting BIG!)

Watched Status: The biggest advantage to using Plex over other media streaming apps is it tracks multiple user's watched status. This status is NOT tracked with most DLNA clients. This status info is tracked in the main database, and can be backed up within Plex's server settings to a location of your own choosing. The main database file can be located here: /volume1/Plex/Library/Plex Media Server/Plug-in Support/Databases You need WinSCP to get to these files.

Plex Start-Stop.sh: This is the actual script that starts the Plex Media Server on the device. It can be found here: /volume1/.@plugins/AppCentral/plexmediaserver/CONTROL You can NOT get to this without WinSCP. There are some modifications to this file needed if you are getting a specific startup error. More on that later!

Cron file: I'm going to refer to this several times in the course of this thread, so I'm going to tell you how to get to it here. It's located at: /volume0/usr/builtin/etc/crontabs and the file is the only one in the folder. It's root with no extension. This is a simple text file and requires WinSCP to access. I just use WinSCP to edit as well.

Assorted scripts: I have scripts for doing media conversions from downloaded sources, PlexPy install, Maraschino (which is currently broken on the Asustor implementation of Python.) As well as various other scripts I want to use, including testing scripts, scripts to check if Plex is running, etc. These are all located here: /volume1/misc I don't need WinSCP to get to these files, but it is handy to modify the scripts contained here using it.

Media Handling:

Plex Media Server shares media to Clients. It is a true Client/Server suite. You basically need both portions to make things work. The server software and the client software. If you don't have a Plex Pass, some of the applications are going to cost you a bit of money. iOS and Android run about $5 client. Buying one does not give you the other. A Plex Pass can be purchased on a monthly, yearly or lifetime basis. You can get more information from Plex's site as to costs, and what clients are available for both Pass and non-Pass users.

There are three ways media is sent to the client:

Direct Play: This is a straight file copy from one device to the other. No conversions are done as none are needed.

Direct Stream: The media is really close to what the client requires for Direct Play, but something is just not right. There are small conversions to the media stream before it is sent out to the client. This is usually not terribly CPU intensive. (I seldom have Direct Stream sessions.)

Transcode: This is a full blown conversion of the media from one file container or codec to another. It is extremely CPU intensive, Plex currently doesn't have any hardware acceleration code in their conversions so it is strictly SOFTWARE BASED. If you don't have at least a 700x series NAS your device CANNOT HANDLE a 1080p stream. None of the newer models are capable of handling the transcoding. The only model that can is the 700x with the i3 CPU in it.

Troubleshooting Plex startup:

Initial Startup: I already pointed you to where the startup script is located. Refer above to it if you don't remember. There are a couple of edits I do to this file every time Plex updates. First off, for some reason Plex seems to start up faster than the system can follow sometimes. So I put a sleep 15 command in the file. I also include a restart section which calls the do-stop and then the do-start in case Plex hangs on me. I have a script running every 20 minutes to make sure Plex is running, and if not it calls the restart. The error that requires the sleep timer is Error: Unable to set up server: basic_string::_S_create If you are getting this error, add in the sleep line here:

Code: Select all

do_start() {
    sleep 15
    check_asdir()
    ulimit -s $PLEX_MEDIA_SERVER_MAX_STACK_SIZE
    (cd $PLEX_MEDIA_SERVER_ROOT ; sleep 3 ; ./Plex\ Media\ Server &)
    return 0
In the Start-stop.sh I also include a restart. Open the file up and make the case section look like this:

Code: Select all

case "$1" in
    start)
        do_start
    ;;
    stop)
        do_stop
    ;;
    restart)
        do_stop
     	sleep 15
        do_start
    ;;
With this in there you can make a script to check if Plex is running and then automatically start and stop it with a single call to the start-stop.sh. More on that with a follow up post.

Local Access: Generally local access issues are going to be problems with accessing the NAS itself. If you can get to your NAS with the following: http://your.internal.IP.here:8000 then getting to the Plex Media Server is going to be: http://your.internal.IP.here:32400/web If you haven't set up your NAS with a static IP you are going to need to do that in order to make port forwarding work for remote access.

Remote Access: Remote access REQUIRES a static IP and ports forwarded through your router for CONSISTENT connections. If you haven't done this, get a copy of your manual for your router and either ask someone to help you or figure it out yourself. I use the myasustor ddns service so I can access my Plex Server as well as the NAS ADM via something like this: http://myidhere.myasustor.com:8000 (ADM) and http://myidhere.myasustor.com:32400. Almost EVERY problem I have helped people with, both on these forums and on Plex's forums for remote access it's solved by static IP and port forward. There was a couple of problems with other networking issues. Things locked out on the ISP side. That was out of the gambit of what we could fix.

You can test if the port is open via several on-line port checking tools. I'll let you look them up yourself.

Video buffering/stuttering:

This was the BIGGEST reason I started this whole post. I made a post a while back about the different CPU's Asustor uses in their various models and what it means for transcoding Plex. (I think it's part of my signature here, even.) This looked at each NAS' CPU passmark score and compared it to Plex's published requirements of 1500 for 720p and 2000 for 1080p transcodes. There is currently only ONE MODEL that supports this requirement! That is the 700x series with over 5000 passmarks.

If you don't have this model of NAS and you are trying to transcode a 1080p stream even locally it is going to buffer! The NAS can't keep up with a real time transcoded stream. It is converting the video as fast as it can, but still slower than you are trying to watch it at. So, how was I able to use a 202T with the smallest CPU Asustor put in any of their various models? I converted the videos over to a Plex Friendly file format and video/audio codecs before I gave them to Plex to serve!

What that means is simple. I ran either Handbrake or some specialize conversion scripts on every file to make sure they were an MP4 with H264 video stream and AAC audio in the first track and no embedded subtitles. On EVERY file! As long as I was watching the movie/show on a network connection that could support the bandwidth requirements of the show it was just like watching it in RT on TV without commercials!

If you are buffering when watching a specific file, try converting that file using Handbrake to MP4, H264, AAC audio and maybe AC3 audio in the second audio stream and see if it still buffers. Odds are great it won't. If it does, then you likely have networking issues. Some things to look at then get rid of wireless connections, stopping all torrenting and stopping all games and test again.

I'm thinking of building on this posts with some more specifics of how my conversions work, renaming files, etc. But this is already pretty long winded. If someone wants to know, ask in this thread or send a PM.

BTW, I have over 1600 movies and well over 12K (Yes, that's 12,000+) TV episodes I stream to 25 users across remote and local access. I've had 7 simultaneous streams going at one time on my 7004T and 5 streams the highest on my 202T. With NO BUFFERING since setting up my media correctly!
Last edited by MikeG.6.5 on Fri Nov 13, 2015 4:30 pm, edited 1 time in total.
MikeG.6.5
Posts: 917
Joined: Fri May 15, 2015 1:56 am

Re: Plex Media Server on your NAS.

Post by MikeG.6.5 »

Installing PlexPy

PlexPy is a way to view historical information about the Plex streaming from your server. As I said above, it requires Python, and in this case you can use the version that comes from App Central. If you just run the PlexPy script as a normal script in a terminal session you WILL see a few errors, but those are the errors associated to SSL, since Asustor still hasn't gotten this working correctly.

You can get PlexPy information as well as some very helpful install instructions and a link to the app itself here: http://forums.plex.tv/discussion/169591 ... program/p1

I made a folder in the /volume1/misc named PlexPy and expanded the files there. Then you need a way to call it as a daemon so you don't need a terminal window open all the time. This is pretty straight forward. Just call it from a terminal window with this line: /volume1/misc/PlexPy/PlexPy.py -d The "-d" tells the OS to start it as a daemon so it runs even after the terminal window gets closed.

PlexPy used to get several updates per day, but it's now pretty stable so doesn't need as many updates, and the guy that did the biggest portion of development has other things on his RL plate now, so he's got less time. As you can see from his screen shots, this is pretty sweet info on historical viewing, and you can track a lot of info on your server's operations with it. How much transcoding or Direct Playing, buffering and some real neat graphs, etc.

It is supposed to also be able to do notifications of when someone starts, stops, pauses, buffers, etc. any media, but the Python errors are giving this fits and starts with PushBullet, so I haven't been able to get this working yet. This is all somehow related to SSL, and basically the same type of errors I saw with Perl on trying to get PlexWatch and PlexWatchWeb running after upgrading my NAS to the 7004T.

After you get it extracted and running, use the paths I already showed you to set up PlexPy to read the log file for Plex and you should start seeing tracking info show up as people use it.

There have been a few times PlexPy would stop working for me. So I did exactly the same type of thing I did to check Plex's remote operations. I used curl to test for a web site at the specified PlexPy port (defaulted to 8181, but you can configure this in the settings pages.)

This script is called ChkPlexPy.sh and is also located in the /volume1/misc folder. After making the file and copying and pasting the script snippet I show below you will have to make sure it is called by cron every few minutes. Here is the code for the script:

Code: Select all

#!/bin/sh

curl -I -m 8 "http://myIDhere.myasustor.com:8181/home";
if [ "$?" -ne "0" ]

then
                /usr/sbin/syslog --log 0 --level 0 --user admin --event "PlexPy isn't running:  Starting it"                
                /volume1/misc/PlexPy/PlexPy.py -d
fi

exit 0
If you don't know how to edit the cron files, refer to the first post for the file name and location. I give the path there. You will need WinSCP to edit this file. It's not visible or editable from within the ADM now. The line I put into the root file (cron file) reads like this: */20 * * * * /volume1/misc/ChkPlexPy.sh This is called every 20 minutes.

This will also send you an AiMaster message if you have your phone configured for it. (The Syslog portion of the code handles notifying you of that if you have AiMaster set up to get messages from the system logs.)

HTH! More coming as I get time and inclination.
MikeG.6.5
Posts: 917
Joined: Fri May 15, 2015 1:56 am

Converting Media to MP4

Post by MikeG.6.5 »

Converting Media to the Plex Friendly file container and codec is pretty simple. You can do it a few different ways.

Manual conversions: You downloaded and installed Handbrake and then have to copy all of the files you convert over to your PC or MAC and do the conversions there. This takes up a lot of time transferring the files, but makes sure you get the files you want converted. If you are doing any transfers over wireless expect it to have failures if you are in a heavy interference environment. (Your neighbors have WiFi on the same 2.4Ghz channels as yours is on.)

Fully automated: You have the scripts from either of Clinton Halls excellent apps, CouchPotato or SickBeard/SickRage and you let these apps tell Plex there is new media added to the library.

Semi Automated: You have specific naming conventions you are trying to maintain so you let the files be converted into a specific watched folder and then run a name checking program like FileBot or TVRename on your media to get the correct names. I put all of the movies into an alphabetic folder scheme with each movie in it's own separate folder as well. I have a total of 28 folders under the main share point so A-Z, # and special characters like the funky AE for Aeon Flux.

There are pros and cons for each method. I prefer the third, as it maintains my folder structure and naming conventions. You are going to have to decide which method you want to use to figure out what's going to work for you. I won't post the scripts I use here. I have a post on Plex's forums of the edits I made to someone else's scripts. If you want mine, you are going to have to get them from that forum and make the same edits I did. At least I provided the editing info to you there.
Last edited by MikeG.6.5 on Tue Jan 05, 2016 12:04 pm, edited 2 times in total.
MikeG.6.5
Posts: 917
Joined: Fri May 15, 2015 1:56 am

Testing Plex is running on the specified port remotely

Post by MikeG.6.5 »

You got Plex up and running, the ports are forwarded to the device and it's set with a static IP. Yet sometimes Plex just dies on it's own. It happens. I have a fairly stable system and I still see it happen about 2 times a week. When it wasn't so stable and I was running on the 202T, I had a lot of times Plex would just die. (Especially when memory was over 80%, thanks to a buggy DLC issue I was having.)

So I wrote another little script to test Plex's availability remotely. This one is a BIT more involved than the other, but not much.... Name this one CkPlex.sh

Code: Select all

#!/bin/sh

curl -I -m 8 "http://youruserId.myasustor.com:32400/web/index.html"
if [ "$?" -ne "0" ]

then
/usr/sbin/syslog --log 0 --level 0 --user admin --event "Remote Access to Plex is unavailable"

                /usr/local/AppCentral/plexmediaserver/CONTROL/start-stop.sh restart
fi

exit 0
This particular script doesn't make use of the restart switch I added to Plex's start-stop.sh, so if you don't want to use that, you can use this script instead:

Code: Select all

#!/bin/sh

curl -I -m 8 "http://youruserid.myasustor.com:32400/web/index.html"
if [ "$?" -ne "0" ]

then
/usr/sbin/syslog --log 0 --level 0 --user admin --event "Remote Access to Plex is unavailable"

                /usr/local/AppCentral/plexmediaserver/CONTROL/start-stop.sh stop
                sleep 5
                /usr/local/AppCentral/plexmediaserver/CONTROL/start-stop.sh start
fi

exit 0
Both of these scripts do exactly the same thing. They stop Plex, give it a rest, then restart it. It just depends on if you want to edit the start-stop.sh or not. As this file changes each time Plex gets updated, you might be better off using the second one.

And remember, we still need to call this script with a cron job. Edit the root file to include this line: */20 * * * * /volume1/misc/CkPlex.sh And as you can see this runs every 20 minutes as well, and also amends to the system logs every time Plex has to be restarted.
Last edited by MikeG.6.5 on Tue Jan 05, 2016 12:04 pm, edited 1 time in total.
MikeG.6.5
Posts: 917
Joined: Fri May 15, 2015 1:56 am

Naming conventions for Movies and Shows

Post by MikeG.6.5 »

Or how to make sure Plex matches the right name to the show you have in your library.

Plex can take a wide range of file names and get the right metadata for your show. BUT, it's much easier to make sure the name is right fromt eh start, and not something way out in left field. If you download your movies or shows you are going to get a lot of really weird stuff in the names and Plex can get really confused by this.

As I mentioned in a previous post, I have 28 folders under the main share level of my movie library. There is A through Z, # and special characters Under each of these I have the name of the movie and year it was released. The movie itself is also named int he same way, and sometimes (if I have more than 1 resolution, especially) I put the resolution in braces as part of the file name.

Example:

/Movies/C/Chappie (2015)/Chappie (2015) [720].mp4 and /Movies/C/Chappie (2015)/Chappie (2015) [1080].mp4.

This is the same movie, just duplicated. There are a couple of reasons to do this, mainly reducing transcoding over-head. It takes less CPU resources to transcode a 720 stream to SD than it does to do a 1080p.

That's movies naming for a Plex friendly name for movies in a nutshell.

TV series follow a similar vein, but no alphabetic folders. (This confuses Plex for some reason. You wind up with all of the "A" series showing as a single series that doesn't get matched to existing shows....)

So I have folders set up with each show listed under the TV Shows shared point, and then separate folders for each season under the show folder. Example: /TV Shows/The Flash (2014)/Season 1/The Flash (2014) - S01E01 - City of Heroes.mp4 I chose this one in particular, since there have been 2 different series called "The Flash." One of them was back in the 80's and then this one in 2014. Originally when I put this show into my library Plex had it listed as the the earlier one, so I had to include the date to make sure it matched correctly.

So, do I name everything by hand? NO WAY! I use FileBot for movies and TVRename for the TV shows. TVRename is sweet, in that once you set up the show it knows where your files are, and as new episodes are download/ripped, it puts them into the right folder and renames the file to the correct naming convention. Sometimes you may have to find the file, but most of the time it does a good job.

Ok, I think I gave enough info for the night. As I think of more I'll post it.
nero78
Posts: 76
Joined: Sat Mar 05, 2016 7:01 pm

Re: Plex Media Server on your NAS.

Post by nero78 »

Thank you so much for this excellent guide! :D Helped me with my startup problems :idea:
richardpoyner
Posts: 8
Joined: Thu May 19, 2016 1:51 am

Re: Plex Media Server on your NAS.

Post by richardpoyner »

This has really helped me a lot. THANK YOU! :)
MikeG.6.5
Posts: 917
Joined: Fri May 15, 2015 1:56 am

Re: Plex Media Server on your NAS.

Post by MikeG.6.5 »

I'm glad you found it useful. I have another Plex guide in the Tips and Tricks section, and you can find it in my signature. As well as a few other significant posts about Plex, Asustor NASes and other tidbits.

I run the 7004T model, which has an i3-4330 CPU in it. So this is a power house compared to some of the other models. What I'm doing with mine would choke some of the other models completely. In fact, most of them would likely just do everything so slowly you would think things had stopped. Everything is still running on them, but no where nearly as fast as if it's just a single task.

Trying to get everything I have on my 7004T running on my 202T would likely be impossible. At almost 20X the CPU, the 7004T has idle time, the 202T just can't compete.
h4nny
Posts: 11
Joined: Fri Mar 28, 2014 3:35 pm

Re: Plex Media Server on your NAS.

Post by h4nny »

Hi Mike, fast question. What version of plex server are you using right now ?

I have small problem the last two revisions http://forum.asustor.com/viewtopic.php?f=67&t=8223

Thanks and regards
saam
Posts: 2
Joined: Fri Sep 23, 2016 6:36 am

Re: Plex Media Server on your NAS.

Post by saam »

h4nny wrote:Hi Mike, fast question. What version of plex server are you using right now ?

I have small problem the last two revisions http://forum.asustor.com/viewtopic.php?f=67&t=8223

Thanks and regards
I was looking for the same thing!
TragusInfantigoDrugs
Post Reply

Return to “Plex”