Tuesday, October 15, 2013

Auto-launch Plex Media Server on Mac OS X

I set out to find a solution that would load Plex Media Server (PMS) as a daemon process at the time my Mac booted.  I found that some folks were actually working on this solution.  The main solution I found was using an open source project, PlexConnect.  I tried a few different attempts at it.  I decided with my lack of interest in setting the whole solution up and the amount of seemingly direct ties to Apple TV, it was not the solution for me.

I found a plist file, com.plex.pms.plist on gtihub.  I dropped this file in to my /Library/LaunchAgents folder.  Soon I discovered the power of launchctl.  I added this plist through launchctl with following command.
launchctl load /Library/LaunchAgents/com.plex.pms.plist
Voila!  PMS was starting.  I tried to quit PMS and suddenly it was starting again.  This seemed promising.  Now I discovered that I had originally set up PMS with the current login.  Later I created a Plex account that then held all of my content.   I also wanted to have PMS auto launch with any of the primary logged in accounts.  This machine will generally have one of the logged in accounts active on the machine.  It is the primary machine for the house.

I started to investigate where PMS stored all of it's information.  I found information regarding for removing PMS from my mac, on the wiki.  Thus, I devised a plan.  I wanted to centralize that data into one location so that I could have any of the primary accounts login and the data presented on my Roku was the right data.

I created a folder in /var named Plex.  I re-created all of the primary directories inside of this folder mimicking the folder structure in a user account and moved those folders from the Plex user account.
  • Library/Application Support/Plex Media Server
  • Library/Caches/PlexMediaServer
  • Library/Preferences/com.plexapp.plexmediaserver.plist
After I moved all of that data to the /var location, I symlinked each of these locations into the two primary accounts as well as the Plex account.  In order to ensure that the data was fully accessible, I also made the /var/Plex/Library folder readable/writable by the Plex account and the group "everyone". This will ensure that if new data is found on my NAS drive holding my data, that it will be added regardless of the account launching PMS.

A relaunch of PMS and the Media Manager showed the information from my library as it was originally set up. This isn't the greatest solution, however, it works and satisfies my needs and requirements.  I could not make much head way with the other solutions or the lack of solution offered by PMS.


5 comments:

  1. Just what I'm looking for. Many thanks. Will try this as soon as I'm home next. ^_^

    ReplyDelete
  2. Very nice, but if I add those two lines:

    /Applications/Plex Media Server.app/Contents/MacOS/Plex DLNA Server
    /Applications/Plex Media Server.app/Contents/MacOS/Plex Media Scanner

    after this line:

    /Applications/Plex Media Server.app/Contents/MacOS/Plex Media Server

    it only starts:

    /Applications/Plex Media Server.app/Contents/MacOS/Plex Media Server

    Why it cannot start all three when booting?


    But when logged in and launchctl it manually, it runs all three of them.

    Is that normal behaviour?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. ...further investigations, show me, that the problem is not what I was trying to solve in the previous message, but this:

    15/08/15 13:57:05,773 Plex Media Server[81]: Untrusted apps are not allowed to connect to Window Server before login.
    15/08/15 13:57:05,773 Plex Media Server[81]: Set a breakpoint at CGSLogError to catch errors as they are logged.
    15/08/15 13:57:05,773 Plex Media Server[81]: This user is not allowed access to the window system right now.
    15/08/15 13:57:05,842 Plex Media Server[81]: _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
    15/08/15 13:57:05,933 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:05,933 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:05,986 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:05,987 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:05,987 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:05,987 Plex Media Server[81]: Invalid Connection ID 0
    15/08/15 13:57:06,016 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:06,016 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:06,041 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:06,041 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:06,041 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:06,045 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.
    15/08/15 13:57:06,045 Plex Media Server[81]: CGSConnectionByID: 0 is not a valid connection ID.

    At boot it runs only Process Name: "Plex Media Server", but not "Plex Plug-in [com.plexapp.system]" and "Plex DLNA Server".

    The complete (of all three services) can load only when I log in and run the command (launchctl load /Library/LaunchDaemons/com.plex.pms.plisthdaemon.plist) manually.

    If any one know how could this be accomplished, please let me know.

    BTW, Im running 10.10.5, all latest apps till this time.

    ReplyDelete