Hey folks, there is a new Podcast category for forums https://forums.plex.tv/categories/podcasts
If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

I really need the ability to launch Plex Media Server on boot up

sleicestersleicester Posts: 3Members, Plex Pass Plex Pass

I have an iMac and use this for my Plex Media Server. With me being away it causes head aches at home as when the computer reboots it doesn't restart PMS as that requires me to log in.

 

The idea solution to this would be the app itself having an option to load on system startup, however even with the ability to run via the command line would allow me to set this up myself. A lot of what I'm reading appears to be older solutions so looking for.

 

Any help and advise appreciated :-)

«1

Comments

  • mutosanmutosan Posts: 425Members, Plex Pass Plex Pass
    edited September 2014

    well, why dont you put it somewhere and apple os is starting the server. I dont know apple os but on windows you can put it into startup folder or make a schedule task. And as apple os is unix, linux pretty near I think it is also possible there.

    Further it is possible to start the plex server by command line so you can easily make a batch file or any other script to fulfill what you want.

    https://forums.plex.tv/topic/48927-how-to-restart-plex-media-server-on-command-line/

  • rsavarsava Posts: 2,626Members, Plex Pass Plex Pass

    You can get it to start automatically. 

    Start up Plex Media Server, go up to the Plex icon in the menu and click on it.

    You should see an option to start Plex automatically.

    Not home right now so I can't tell you exactly what it is called. Will post later when I get home if you can't find it. Post back here so I will be reminded.

    R Sava

  • atrusatrus Posts: 11,100Members, Plex Pass, Plex Ninja Plex Ninja
    edited September 2014

    OP is saying that when he is away from home and the computer is restarting, there is no one around to log him in. And a user needs to be logged in to start an app.

    I have never tried this, but I suspect it might be possible to start up an app if you login via SSH even though no one is logged in sitting physically by the computer, as long as the app does not require an OpenGL context (which I think quite a few does). I do not know if this works with PMS, but you can try it. There are SSH clients available for whichever smartphone you have, so you can control it whenever.

    SSH in to your iMac with the user you usually log in with. Then run this command (if you have PMS in your Applications folder of course):

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

    Does it work?

     Mac mini 2,3 GHz Quad-Core Intel Core i7 (With Fusion drive) (PM score: 7347)  Panasonic VT50 (55 inch)  Pioneer VSX-2021 Receiver  Norco 24-bay NAS (CPU: Intel Xeon E3-1240v2 3,4GHz, PM score: 9300) 
    New to Plex/Nine? Watch my screencast video (slightly out-dated nowadays, but still informative for new users)
    Want to know how to handle subtitles? Watch my subtitle screencast video (out-dated, but still informative), and this One Minute Subtitle Addendum screencast
    Always attach log files if you are reporting an issue: Log file info & location
    Get Plex guides here: Howto name your files NAS guide Troubleshooting Plex Support Page
  • DarwinnerDarwinner Posts: 27Members ✭✭

    1. System Preferences > Users & Groups > Login Options > Automatic Login: "pick user from drop down menu"

    +

    2. Have "Open at login.." checked in the pms menubar for that same user.

    This is the most accessible way for most users of doing this on OS X and is perfectly fine, especially if you're the only user.

    The alternative is running a launch Daemon/Agent script, but thats a solution to a scale problem you never claimed to have.

    Servers:

    Yosemite Hackintosh running on i5-3570k (overclocked)

    Windows 7 running on AMD Athlon 64 x2 6000+

    Client devices:

    WDTV live smp (gen3)

    Rasberry Pi model B+

  • atrusatrus Posts: 11,100Members, Plex Pass, Plex Ninja Plex Ninja
    Darwinner wrote on September 17 2014, 2:22 PM: »

    1. System Preferences > Users & Groups > Login Options > Automatic Login: "pick user from drop down menu"

    +

    2. Have "Open at login.." checked in the pms menubar for that same user.

    This is the most accessible way for most users of doing this on OS X and is perfectly fine, especially if you're the only user.

    The alternative is running a launch Daemon/Agent script, but thats a solution to a scale problem you never claimed to have.

    I assume that he has the login window after reboot because he want security. But... hmm... what he can do is use your method, but set the screensaver to 1 minute, and add a password demand to when going out of screensaver mode. That minimises the security risk. At least a little bit =)

     Mac mini 2,3 GHz Quad-Core Intel Core i7 (With Fusion drive) (PM score: 7347)  Panasonic VT50 (55 inch)  Pioneer VSX-2021 Receiver  Norco 24-bay NAS (CPU: Intel Xeon E3-1240v2 3,4GHz, PM score: 9300) 
    New to Plex/Nine? Watch my screencast video (slightly out-dated nowadays, but still informative for new users)
    Want to know how to handle subtitles? Watch my subtitle screencast video (out-dated, but still informative), and this One Minute Subtitle Addendum screencast
    Always attach log files if you are reporting an issue: Log file info & location
    Get Plex guides here: Howto name your files NAS guide Troubleshooting Plex Support Page
  • eckartheckarth Posts: 502Members, Plex Pass Plex Pass
    atrus wrote on September 17 2014, 1:13 PM: »

    OP is saying that when he is away from home and the computer is restarting, there is no one around to log him in. And a user needs to be logged in to start an app.

    I have never tried this, but I suspect it might be possible to start up an app if you login via SSH even though no one is logged in sitting physically by the computer, as long as the app does not require an OpenGL context (which I think quite a few does). I do not know if this works with PMS, but you can try it. There are SSH clients available for whichever smartphone you have, so you can control it whenever.

    SSH in to your iMac with the user you usually log in with. Then run this command (if you have PMS in your Applications folder of course):

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

    Does it work?

    That in not going to work, as the PMS will be a child process of the login shell. I.e. it dies when he logs out again. Framing your command in "nohup .... &" might work (i.e. I have not tested it). That will detach the PMS process from the shell and keep it running even after the parent terminated.

    But why would he want to ssh into his server in the first place. Someone would need to tell him that his server deceased. He needs a launchctl construct which starts PMS during the boot process. But I have not tested that either. But I strongly feel that that is the way a server process should be properly launched. I am sure the Plex guys know that too. Hence, either they are slowly migrating there too, or there is a stumble stone in the way. 

  • hrm3hrm3 Posts: 3Members, Plex Pass

    This is something that would be a big benefit to me as well.  It never fails, when I'm away from the house is when we have a power issue.  The imac is set to auto restart after a power failure, but i do not want to set automatic login (for a number of security reasons) - which means plex media server will not start.   If it could be set to run as some sort of system service that wouldn't need user login to start, that would be excellent.

  • ChristoffeeChristoffee Posts: 201Members, Plex Pass Plex Pass
    What about an uninterrupted power supply?
  • sleicestersleicester Posts: 3Members, Plex Pass Plex Pass

    Thanks for the replies people.

    I'm quite comfortable with doing things via the shell but my experience seems to be confirmed in that PMS can't run simply as a daemon and comes as a complete package which requires a user to be logged in, and provides other nice UI elements. It would be great if the basics of running the server could be run independently so you could set them up to run on boot (via launchctl) - that's my preference.

    I've seen another article that talks about setting up auto login that then immediately locks the machine - that might be the route I need to take for now.

    It's a shame that I have the old Drobo, the newer one would handle all of this from source. 

  • hrm3hrm3 Posts: 3Members, Plex Pass

    As far as a UPS goes, that's kinda a solution but doesn't solve the issue if it's an extended power outage longer than the UPS can keep standing.  agree with sleicester, that ability to run the media serving part at boot would be ideal.

  • DarwinnerDarwinner Posts: 27Members ✭✭
    sleicester

    I'm quite comfortable with doing things via the shell

    Considering you hadn't declared your goals, environment or expected number/type of users here I was hoping help you avoid my own mistakes when it comes to spending the appropriate amount of time on task, even though it can be fun.

    The good news is starting plex media server with a launch daemon does run fine for myself and has for a while as far as I can tell.

    I'm currently on OS X 10.9.4 and PMS 0.9.10.1.585

    I run PMS as a user named "_plex".

    I don't know if its unsafe or incorrect but the above is a networked-user (mac open-directory) in case I one day wanted to "scale-out".

    The main server hasn't yet had over 5 concurrent streams (trans + direct) and it also serves as my workstation.

    Though I might soon allow more with new users over my 10mbs up cable connection.

    A remote server at family's house (7 users) runs as a service on windows7 but is a 7yr old low end AMD.

    Real problems this solves for me:

    - *automatic reboots after power-loss will allow PMS to startup without human aid (e.g. I'm out of town for a week,month,months)

    - *my personal account won't be logged in by default on reboot. Only a "real" problem when multiple users have access. Solve this by running plex as its own user

    - Any (plex user) account won't be logged in by default on reboot. Only a "real" where other users may be ignorant(most cases), careless or untrustworthy.

    * star indicates those also solved by auto-login + startup items

    Things that still bother me with this setup:

    - strange behaviour with plex menubar item : when pms is run by user "_plex" the menubar icon appears for my personal account,

    functionally this is rather nice however from a security standpoint this should not happen. Still haven't had time to investigate/correct this.

    - as far as I can tell, pms won't run as a true daemon, i.e. "sleep" when unneeded to save cpu time/power. However, thats probably for the best and avoids an array of other potential silly problems such a performance and latency.

    I will make another post with the launch daemon plist file I'm using.

    However, based on Apple's documentation for an up-to-date secure solution(enterprise deployment or selling a product) it seems an XPCD service is the way to go.  Hence the need to declare your goals, to avoid too much work vs getting fired over too little.

    Servers:

    Yosemite Hackintosh running on i5-3570k (overclocked)

    Windows 7 running on AMD Athlon 64 x2 6000+

    Client devices:

    WDTV live smp (gen3)

    Rasberry Pi model B+

  • DarwinnerDarwinner Posts: 27Members ✭✭
    edited September 2014

    Here's my script, sorry for the wait.

     

    It goes in "/Library/LauchDaemons/".

    I named mine "tv.plex.service.plist"

     

    Root MUST be the owner.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    	<key>GroupName</key>
    	<string>_plex</string>
    	<key>KeepAlive</key>
    	<dict>
    		<key>SuccessfulExit</key>
    		<false/>
    	</dict>
    	<key>Label</key>
    	<string>tv.plex.service</string>
    	<key>ProgramArguments</key>
    	<array>
    		<string>/Applications/Plex Media Server.app/Contents/MacOS/Plex Media Server</string>
    	</array>
    	<key>RunAtLoad</key>
    	<true/>
    	<key>StandardErrorPath</key>
    	<string>/tmp/tv.plex.service.err</string>
    	<key>StandardOutPath</key>
    	<string>/tmp/tv.plex.service.out</string>
    	<key>UserName</key>
    	<string>_plex</string>
    </dict>
    </plist>
    
    

    Once file is in place, the script must be loaded (or "unload") so its launched on a restart:

    sudo launchctl load -w /Library/LaunchDaemons/tv.plex.service.plist

    To have it start (or "stop") immediately use the following:

    sudo launchctl start tv.plex.service

    It might not be perfect, but its working at least.

    Servers:

    Yosemite Hackintosh running on i5-3570k (overclocked)

    Windows 7 running on AMD Athlon 64 x2 6000+

    Client devices:

    WDTV live smp (gen3)

    Rasberry Pi model B+

  • crystalreefcrystalreef Posts: 18Members, Plex Pass Plex Pass

    Hi Darwinner,

    I'm trying your solution but can't seem to get it to run.

    i have created a local user _plex logged in and run plea so it is all connected and can be seen etc. logged out.

    I have created the plist and placed in macintosh hd/library/launchdaemons

    changed owner to root

    but it just won't start the server.

    Any ideas?

    Thanks

  • eckartheckarth Posts: 502Members, Plex Pass Plex Pass
    edited September 2015 via Email
    You did load the new plist in LaunchDaemons? > sudo launchctl load /Library/LauchDaemons/.....plist
    or reboot.

    If you did, check /var/log/system.log for messages.

    I have actually never used this myself.

    Eckart
  • crystalreefcrystalreef Posts: 18Members, Plex Pass Plex Pass

    Yes.

    Just get this in the log but the file is there

    Sep 4 22:43:05 mymac com.apple.xpc.launchd[1] (com.plex.pms[1038]): Could not find and/or execute program specified by service: 2: No such file or directory: /Applications/Plex\ Media\ Server.app/Contents/MacOS/Plex\ Media\ Server

    if I paste the path into terminal Plex starts so I know it is right.

  • cbrunnercbrunner Posts: 4Members, Plex Pass Plex Pass

    Hi folks,

    I feel like I'm very close to getting this working. I'm using Darwinner's plist file, and the process actually starts upon boot, but PMS is totally inaccessible and doesn't seem to be functioning, despite that the process is running. Port 32400 remains closed, for example.

    There's no Plex-related output in my system log, but tv.plex.service.err yields the following output:
    _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL. 2015-12-04 17:08:01.781 Plex Media Server[299:2848] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 2015-12-04 17:08:01.781 Plex Media Server[299:2848] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 2015-12-04 17:08:01.782 Plex Media Server[299:2848] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 2015-12-04 17:08:01.782 Plex Media Server[299:2848] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data

    Can anyone help me figure out what the issue might be? Thanks in advance for any assistance.

  • cbrunnercbrunner Posts: 4Members, Plex Pass Plex Pass
    edited December 2015

    One more interesting tidbit:

    When I start PMS from the CLI (via SSH) while I am logged in via the desktop, it works fine:
    Chriss-Mac-mini:Logs chris$ "/Applications/Plex Media Server.app/Contents/MacOS/Plex Media Server" mach_msg failed with error code 10004002

    (Despite the mach_msg error, Plex starts and functions normally.)

    However, when I SSH into my Mac prior to logging in (to simulate what happens when autolaunch starts the PMS process, I get the following output. The process continues to run, but Plex never starts or functions in any detectable way.

    Chriss-Mac-mini:Logs chris$ "/Applications/Plex Media Server.app/Contents/MacOS/Plex Media Server" mach_msg failed with error code 10004002 Dec 4 17:52:52 Plex Media Server[614] <Error>: Set a breakpoint at CGSLogError to catch errors as they are logged. Dec 4 17:52:52 Plex Media Server[614] <Error>: This user is not allowed access to the window system right now. _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL. Dec 4 17:52:52 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:52 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: Invalid Connection ID 0 Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. 2015-12-04 17:52:53.626 Plex Media Server[614:11286] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 2015-12-04 17:52:53.627 Plex Media Server[614:11286] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 2015-12-04 17:52:53.627 Plex Media Server[614:11286] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data 2015-12-04 17:52:53.628 Plex Media Server[614:11286] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID. Dec 4 17:52:53 Plex Media Server[614] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.

    So, this is clearly not a problem related to OS X, but rather an issue with getting PMS to run headless on OS X. To amend my question, how do I get PMS to run headless as it does on my Linux NAS?

    Thanks again, in advance, for any assistance that anyone can offer!

  • lee.joneslee.jones Posts: 7Members, Plex Pass Plex Pass
    edited January 2016

    Hi all,

    It might not be perfect, but its working at least.

    Has it proved to be successful in the over a year since you posted your script (thanks BTW) or have you come across issues?

    Also how did you create the user? I use the following script in this post on serverfault.com to create daemon users. Just curious as to whether you had to give the user any special permissions etc?

    Thanks and happy new year to you all.

    Edit

    It's not working yet. I'm going to run as my logged in user as its now 5pm and I've been up since 2:30am. I'll continue tomorrow and will report my findings. It's most likely a simple case of the app doesn't support being run as a daemon level user - goes without saying since theres no documentation relating to this AFAIK - most of the error messages in the logs relate to accessing the WindowServer which such a user wouldn't be able to do.

    Edit

    I just wrote the following in another thread on this subject:

    '...I've come to the conclusion its not going to happen without support from the development team/worth additional effort.

    As an alternative I'm going to create a standard user which will be set as the auto-login user and move PMS to that user as well as various other web apps I run that will likely be problematic also. It's the quickest route to ensuring your personal data cannot be accessed if a vulnerability was discovered in the software. I feel a bit stupid for not going this route at the start but I've learned a few new tricks this afternoon so it was worth it.'

  • ematrejekematrejek Posts: 8Members ✭✭
    edited April 2016

    Has there been any further developments on running the Launch Daemon? I commented in another thread that I'm experiencing the same scenario. This should not be too difficult for the Plex team to remedy.

  • lilmonkeylilmonkey Posts: 1Members, Plex Pass Plex Pass

    I love Plex...but after adding a second account to my Mac, I've found the only way to keep Plex running is to be signed into my primary account. Bummer.
    This would be a huge add, in my opinion.

«1
Sign In or Register to comment.