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.