init.d script for Plex Media Server for Ubuntu

Run plex media server as a daemon
I figure I'm not the only one who would like Plex Media Server to run as a daemon on Ubuntu instead of running in the foreground, so I thought I'd share an init.d script I pieced together.

Usage is fairly simple, just rename and moved the attach file to /etc/init.d/plexmediaserver (or name it however you like), after you have set the RUNAS and SCRIPTPATH variables to the user you want the server to run as, and the full path to where the binary lives. It seems that init.d scripts don't like executables with spaces in their names (as far as I could tell), so I've built in a check that will rename the "Plex Media Server" binary to just PlexMediaServer, if needed.

Once you've done that, you can just do

service plexmediaserver start


to start the server up. Unfortunately I wasn't able to get it to support logging output to a file - hopefully the Plex team can compile in support to specify where to redirect stdout and stderr.

Here's general usage:

Usage: /etc/init.d/PlexMediaServer {start|stop|restart|reload|force-reload|status}

(You can see this by just doing ‘service plexmediaserver’)



Also, if you’d like to have it start automatically when your machine boots up:


sudo update-rc.d plexmediaserver defaults


I haven't tested this out yet, but it should work.

I don't have a readyNAS or run Slackware, but I imagine someone can repurpose this for those. Feel free to share here if you do.

Please let me know if anyone has problems, or suggestions. I imagine the server itself will probably be updated to support this kind of thing eventually, but I got impatient :)

Also, I initially attempted to create a Makefile that could move the binaries to somewhere like /usr/local/bin, and all the lib files and the Resources directory to somewhere like /var/lib/Plex, but unfortunately the server binary expects the Resources directory to be in the same place as itself, since it needs the python executable. I’ve asked Elan if it would be possible to get a recompiled binary that looks for it using LD_LIBRARY_PATH but haven’t heard back yet so just having it run from wherever you untar it to should work for now.

Has anybody tried this, as I have just followed the instructions and cant for the life of me get it to work.



It is a real let down not to be able to get Plex to start on autoboot.



I would really appreciate some assistance in the development of this so I dont need to interact with the OS to have Plex running…



Cheers

Awesome, works for me. Thanks for that, Jack. I just created /usr/local/bin/plex and put everything in there and amended the script to point at that. Had to run the script as sudo the first time to get it to rename the binary to be without spaces, but everything was fine after that (and I’d chowned it all to belong to the user I’m running it as). Had tried a much less elegant solution but was stuck on the spaces in the binary name issue.



What’s the problem, msaggers?

I’m having a problem running Plex as a non-admin user. Any ideas? Details.

First up thanks for taking the time to create this.



Now to try and help out the people with problems. One thing I had to do to get it working was to make the script executable, with this command:

sudo chmod 755 /etc/init.d/PlexMediaServer



After doing that I ran it as root once to get it to work correctly:

sudo /etc/init.d/PlexMediaServer start



After that I could run it using service, but I had to make this command use the proper case:

service PlexMediaServer start



When I do use this command to stop Plex it still leaves some python script running which I have to kill by hand, shouldn’t everything be stopped?

For example I still see the process:

***** 17247 38.4 4.2 103408 37648 ? SNl 11:33 2:30 Plex Plug-in [com.plexapp.system] /home//Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py --server-version v0.9.2.8-34480ac /home//Library/Application Support/Plex Media Server/Plug-ins/System.bundle



I just wanted to ask the person who moved everything to /usr/local/bin. Did that include moving the Library folder, or just the executables? If we do have to have a Library folder then maube we need a good tutorial from start to finish to show people how to set up a separate Plex user to keep all this stuff self contained?

Is it possible to run this as “root” so that you don’t have to log in for the service to be running?

Ok… so I set the username as “root” in the init.d/plex script. What this does is add the Library folder to /root/Library.



This is kind of gross but it appears to work on bootup without having to login to any user account which is precisely what I want to be able to do. If I set the username as my admin user account I need to login before plex works properly.



Am I doing this horribly wrong or is this the only way to achieve the same goal?

Here's another one I found somewhere along the way:

https://github.com/tripflex/iPlex/blob/master/etc/init.d/plexmediaserver

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.