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

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 :-)

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/

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.

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?

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.

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 =)

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. 

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.

What about an uninterrupted power supply?

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. 

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.

<span><a  class="" href="https://forums.plex.tv/user/215021-sleicester/" title="">sleicester</a></span>

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.

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"?>



	GroupName
	_plex
	KeepAlive
	
		SuccessfulExit
		
	
	Label
	tv.plex.service
	ProgramArguments
	
		/Applications/Plex Media Server.app/Contents/MacOS/Plex Media Server
	
	RunAtLoad
	
	StandardErrorPath
	/tmp/tv.plex.service.err
	StandardOutPath
	/tmp/tv.plex.service.out
	UserName
	_plex


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.

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

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

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.

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.

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!

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.’

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.