Linux install for Plex Connect

Hi,

Will this method run on a ClearOS server? It uses dnsmasq for DHCP and DNS. I'm not sure yet to run Plexconnect on my Synology or ClearOS server. Maybe i'm going to sell the Synolgy unit and it would be nice if i can make this running on my ClearOS server. 

Hi all,

I have installed PMS onto my Ubuntu Server 12.04 with no issues

I have installed and run PlexConnect OK and my Apple TV trailers work fine.  However as the SSH pipe drops from my iMac to the Server I loose the PlexConnect hack.

I worked thru this to try and get PlexConnect to start at boot on the server.  All of step 4 seemed to go fine, however when I do:          sudo update-rc.d plexconnect defaults

I get the following error:

update-rc.d: warning: plexconnect start runlevel arguments (2 3 4 5) do not match LSB Default-Start values (3 4 5)
 System start/stop links for /etc/init.d/plexconnect already exist.

As a complete Newbie to Ubuntu, I have no idea what this means or how to fix...... any help would be appreciated.  I dont want to dump my ATV3 and buy a Roku, just to fix this!

rgds

Alistair

In my case it's exactly like that… The error/warning is like Hollymoons.

Have you set the service to start automatically ? It is part of the last steps in the post.

 

sudo chown root:root /etc/init.d/plexconnect
sudo chmod 755 /etc/init.d/plexconnect
sudo update-rc.d plexconnect defaults

 

These instructions will cause update-rc.d to read the comments at the top of the script (shown below) and setup the daemon appropriately. Do you also have a daemon called plexmediaserver on the server that you are installing plexconnect on? If not remove plexmediaserver from the Required-Start and Required-Stop entries or else the daemon won't start since there is not a running plexmediaserver.

Of course I didi all the steps… The error is the one mentionend above.

I do have a running plexmediaserver-deamon on the Ubuntusystem, so it should work, so far I understand it, anyway…

Strange though, after the last update, the deamon doesn't get startet via 'sudo service plexconnect start'.

I just get:

*Plexconnect process is not running

*Starting the process PlexCOnnect

But when I type 'sudo service plexconnect status'

I get the status 

*PlexConnect process is not running

Strange… I absolutely don't know what to do to get kit working…

I have done some modifications from the ubuntu initscript to make it compatible with Debian and PMS for Debian (see Debian release thread becuase one thing is needed to be changed in PMS initscript as well)

#!/bin/bash
### BEGIN INIT INFO
# Provides:          plexconnect
# Required-Start:    plexmediaserver
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: This is the Plex Connect daemon
# Description:       This script starts the Plex Connect
#                    Python scripts in a detached screen.
### END INIT INFO

# Using the lsb functions to perform the operations.
. /lib/lsb/init-functions

# Process name ( For display )
NAME=PlexConnect

# Daemon name, where is the actual executable
DAEMON="/usr/bin/screen"
DAEMON_OPTS="-S PlexConnect -d -m /locationtoplexconnect/PlexConnect/PlexConnect.py"
DAEMON_USER="root"

# pid file for the daemon
PIDFILE=/var/run/PlexConnect.pid

# If the daemon is not there, then exit.
test -x "$DAEMON" || exit 5

case $1 in
 start)
  # Checked the PID file exists and check the actual status of process
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE "$DAEMON $DAEMON_OPTS" "$NAME process" && status="0" || status="$?"
   # If the status is SUCCESS then don't need to start again.
   if [ $? = "0" ]; then
    log_success_msg "Starting the process $NAME"
    exit # Exit
   fi
  fi
  # Start the daemon.
  # Start the daemon with the help of start-stop-daemon
  # Log the message appropriately
  if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -p $PIDFILE -- ${DAEMON_OPTS}; then
   while read line ; do [[ $line =~ ([0-9]*).PlexConnect ]] && echo ${BASH_REMATCH[1]} ; done < <(screen -ls) > $PIDFILE
   log_success_msg "Starting the process $NAME"
  else
   log_failure_msg "Starting the process $NAME"
  fi
  ;;
 stop)

  # Stop the daemon.
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE "$DAEMON DAEMON_OPTS" "Stoppping the $NAME process" && status="0" || status="$?"
   if [ "$?" = 0 ]; then
    start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
    /bin/rm -rf $PIDFILE
    log_success_msg ""Stopping the $NAME process""
   fi
  else
   log_failure_msg "$NAME process is not running"
  fi
  ;;
 restart)
  # Restart the daemon.
  $0 stop && sleep 2 && $0 start
  ;;
 status)
  # Check the status of the process.
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE "$DAEMON $DAEMON_OPTS" "$NAME process" && exit 0 || exit $?
   log_success_msg "$NAME process is running"
  else
   log_failure_msg "$NAME process is not running"
  fi
  ;;
 reload)
  $0 restart
  ;;
 *)
  # For invalid arguments, print the usage message.
  echo "Usage: $0 {start|stop|restart|reload|status}"
  exit 2
  ;;
esac

After changing out to your new startup script, does it have to be re-registered?   Could you tell us the steps needed to change-out the script for Ubuntu 12.04?

In my case it's exactly like that… The error/warning is like Hollymoons.

Of course I didi all the steps… The error is the one mentionend above.

I do have a running plexmediaserver-deamon on the Ubuntusystem, so it should work, so far I understand it, anyway…

Strange though, after the last update, the deamon doesn't get startet via 'sudo service plexconnect start'.

I just get:

*Plexconnect process is not running

*Starting the process PlexCOnnect

But when I type 'sudo service plexconnect status'

I get the status 

*PlexConnect process is not running

Strange… I absolutely don't know what to do to get kit working…

deLoco,

I had the problem that as I was doing trial and error to get this startup script configured properly, somewhere along the way the /var/run/PlexConnect.PID file got created by the script, but didn't get properly deleted when the PlexConnect was no longer running.   Apparently, the script creates that file, to exist only while the PlexConnect process is running.   Not sure exactly where in the shutdown it should be deleted, but in my case somehow the file didn't get deleted properly at some point.  Thus, in my case, the PlexConnect startup script would never startup the PlexConnect again, until I deleted that file by following step to remove that file (don't worry the script will create the file again the next time a startup is attempted).

$ sudo rm /var/run/PlexConnect.PID

Hope maybe that helps you, and any others that struggle to make this work.

Additional Tips for running the plexconnect startup script on Ubuntu 12.04.  I finally have the startup working on my Ubuntu 12.04 in a VMware VM.  This works very well now.  The most crucial tidbit is that a delay was needed to be injected into the start portion of the script (which is what got my setup working after hours of trial an error and looking at logs).   Specifically I added a 15 second delay to the following section of code.

# Start the daemon.
# Start the daemon with the help of start-stop-daemon
# Log the message appropriately
sleep 15              # <========== This is the best place (I could find to add) the 15 second sleep, and Ubuntu 12.04 now works
if start_daemon -u $DAEMON_USER -p $PIDFILE $DAEMON $DAEMON_OPTS; then
while read line ; do [[ $line =~ ([0-9]*).PlexConnect ]] && echo ${BASH_REMATCH[1]} ; done < <(screen -ls) > $PIDFILE
 

Additionally, (on Ubuntu 12.04 x86_64 Desktop), I registered the script into the LSB init.d system with following command:

$ sudo update-rc.d plexconnect defaults 95 05
 

I'd really like to say huge thanks to f00b4r for the development of PlexConnect, and a little smaller thanks to wilsoncd2 for his help via his shared experience by the postings I've found on this forum.   (the startup script he provided allowed packaging the PlexConnect service up in a VM as an appliance I can be easily started-n-stopped at will, contained in it's own sandbox).

BTW, you might think the overhead of a VM might slow things, but a couple hours testing reveals no hickups, it runs just as well as it did against bare-metal (the VMware server is also pretty beefy...6 cores @ 3.6 GHz....but my guess is you don't "need" nearly that much power for PlexConnect).

To be honest, I dont have any problems running plexconnect without any kind of delay on ubuntu (server) 12.04, but server and desktop shouldnt make any difference here

Baa and Roidy deserve most of the credit for the code (along with a few nice contributions by others).

PlexConnect shouldn't need any real power, you can run it on a jailbroken ATV or on a Tomato router, the power is needed at the PMS end if you media requires transcoding. ;)

Thank for your guide. I'm running CentOS 6.4, but the plexconnect process went dead when I start the init script. 

I've tried using  zdaemon instead. It works fine too.

So, I want to add it here for someone who might have the same problem as mine.

%> easy-install zdaemon

then, create file "/usr/local/lib/plexconnect/plexconnect.sh"

#! /bin/bash
# Daemon name, where is the actual executable
/usr/bin/zdaemon -p "python /usr/local/lib/plexconnect/PlexConnect.py" -d $@

create init script "/etc/init.d/plexconnect"

#! /bin/bash
#
# PlexConnect.
#

PLEXCONNECT_HOME=/usr/local/lib/plexconnect
PLEX_USER=root
/bin/su - $PLEX_USER PLEXCONNECT_HOME/plexconnect.sh @

%>chmod +x /usr/local/lib/plexconnect.sh
%>chmod +x /etc/init.d/plexconnect
 

set the service to start as usual

%> chkconfig plexconnect on

$ sudo rm /var/run/PlexConnect.PID

 

Hope maybe that helps you, and any others that struggle to make this work.

Hmmm… Yeah, that works, but I have to delete the PlexConnect.PID manually every time… 

So it's not a real solution, only a hint o what problem to solve…

So it seems, that PlexConnect.PID doen't get deleted when the service gets stopped. When I remove the file, the service can be started again…

Why doesn't the pid-file get deleted? I don't understand, after all, I just copied the script from this post, and didn't edit anything…

I am still struggling with the init script for PlexConnect.

I seem to have tried all options here and still get the following error



sudo update-rc.d plexconnect defaults

update-rc.d: warning: plexconnect start runlevel arguments (2 3 4 5) do not match LSB Default-Start values (3 4 5)

System start/stop links for /etc/init.d/plexconnect already exist.


As a complete novice to Ubuntu I am finding this very frustrating… have even tried changing the start values to be 2 3 4 5 … no good


Plexconnect works fine through the ssh pipe. I so need to get this working and need some help please.


my /etc/init.d/plexconnect is:



#!/bin/bash

BEGIN INIT INFO

Provides: plexconnect

Required-Start: plexmediaserver networking

Required-Stop: plexmediaserver networking

Default-Start: 3 4 5

Default-Stop: 0 1 6

Short-Description: This is the Plex Connect daemon

Description: This script starts the Plex Connect

Python scripts in a detached screen.

END INIT INFO

Using the lsb functions to perform the operations.

. /lib/lsb/init-functions

Process name ( For display )

NAME=PlexConnect

Daemon name, where is the actual executable

DAEMON="/usr/bin/screen"

DAEMON_OPTS="-S PlexConnect -d -m /var/lib/PlexConnect/PlexConnect.py"

DAEMON_USER=“root”

pid file for the daemon

PIDFILE=/var/run/PlexConnect.pid

If the daemon is not there, then exit.

test -x “$DAEMON” || exit 5


case $1 in

start)

Checked the PID file exists and check the actual status of process

if [ -e $PIDFILE ]; then

status_of_proc -p $PIDFILE “$DAEMON $DAEMON_OPTS” “NAME process" && status="0" || status="?”

#pidofproc -p $PIDFILE > /dev/null 2>&1

If the status is SUCCESS then don’t need to start again.

if [ $? = “0” ]; then

log_success_msg “Starting the process $NAME”

exit # Exit

fi

fi

Start the daemon.

#log_daemon_msg “Starting the process” “$NAME”

Start the daemon with the help of start-stop-daemon

Log the message appropriately

sleep 15 # <========== This is the best place (I could find to add) the 15 second sleep, and Ubuntu 12.04 now works

if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -p PIDFILE -- {DAEMON_OPTS}; then

#if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON $DAEMON_OPTS; then

#if start_daemon -u $DAEMON_USER -p $PIDFILE $DAEMON $DAEMON_OPTS; then

while read line ; do [[ line =~ ([0-9]*).PlexConnect ]] && echo {BASH_REMATCH[1]} ; done < <(screen -ls) > $PIDFILE

log_success_msg “Starting the process $NAME”

else

log_failure_msg “Starting the process $NAME”

fi

;;

stop)

Stop the daemon.

if [ -e $PIDFILE ]; then

status_of_proc -p $PIDFILE “$DAEMON DAEMON_OPTS” “Stoppping the NAME process" && status="0" || status="?”

#pidofproc -p PIDFILE > /dev/null 2>&1<br> if [ "?" = 0 ]; then

start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE

#killproc -p $PIDFILE

/bin/rm -rf $PIDFILE

log_success_msg ““Stopping the $NAME process””

fi

else

log_failure_msg “$NAME process is not running”

#log_end_msg 0

fi


else

log_failure_msg “$NAME process is not running”

#log_end_msg 0

fi

;;

restart)

Restart the daemon.

$0 stop && sleep 2 && $0 start

;;

status)

Check the status of the process.

if [ -e $PIDFILE ]; then

status_of_proc -p $PIDFILE “$DAEMON $DAEMON_OPTS” "NAME process" && exit 0 || exit ?

#pidofproc -p $PIDFILE > /dev/null 2>&1

log_success_msg “$NAME process is running”

else

log_failure_msg “$NAME process is not running”

#log_end_msg 0

fi

;;

reload)

$0 restart

;;

*)

For invalid arguments, print the usage message.

echo "Usage: 0 {start|stop|restart|reload|status}"<br> exit 2<br> ;;<br> esac<br><br> as an edit if I run Plexconnect via ssh my settings are:<br><br> ~/PlexConnect sudo ./PlexConnect.py

11:29:48 PlexConnect: started: 11:29:48

11:29:48 PlexConnect: ***

11:29:48 PlexConnect: PlexConnect

11:29:48 PlexConnect: Press CTRL-C to shut down.

11:29:48 PlexConnect: ***

11:29:48 PlexConnect: IP_self: 192.168.1.87

11:29:48 PlexConnect: started: 11:29:48

11:29:49 DNSServer: started: 11:29:49

11:29:49 DNSServer: ***

11:29:49 DNSServer: Starting up.

11:29:49 DNSServer: intercept trailers.apple.com: 192.168.1.87

11:29:49 DNSServer: forward other to higher level DNS: 8.8.8.8

11:29:49 DNSServer: ***

11:29:49 WebServer: started: 11:29:49

11:29:49 WebServer: ***

11:29:49 WebServer: WebServer: Serving HTTP on 0.0.0.0 port 80.

11:29:49 WebServer: ***

11:29:49 PlexGDM: ***

11:29:49 PlexGDM: looking up Plex Media Server

11:29:49 PlexGDM: ***

11:29:50 PlexGDM: servers discovered: 1

11:29:50 XMLConverter: PlexGDM - PMS: 192.168.1.87:32400


this works fine and I can access via my ATV3 without a problem till the pipe goes down…



I am even willing to offer someone “in the Know” remote connection to my server to see if they can sort…


hoping for some help here.


many thanks

Alistair

I'm running this on CentOS 6.4 and it's running great as a daemon with your instructions. Thanks a ton for writing them.

I have installed Python 2.7 as a separate install so that any 2.6 dependencies weren't broken. What do I have to change in the PlexConnect and/or Screen daemon setup so that it's launched using Python 2.7 and not the default Python 2.6? No idea what I have to change and I don't want to break anything since I finally have everything running perfectly.

With help of this thread (and some other resources) I have posted an how-to for PlexConnect in combination with a Linux Debian Server and a non-default listen-port on my blog on http://eye-vision.homeip.net/1408/plexconnect-en-appletv-met-debian/. It is in Dutch, but I guess with Google Translate you can figure out what I did ;-).

I'm running this on CentOS 6.4 and it's running great as a daemon with your instructions. Thanks a ton for writing them.

I have installed Python 2.7 as a separate install so that any 2.6 dependencies weren't broken. What do I have to change in the PlexConnect and/or Screen daemon setup so that it's launched using Python 2.7 and not the default Python 2.6? No idea what I have to change and I don't want to break anything since I finally have everything running perfectly.

Anyone?

Hey guys,

I think an edit is needed for this.

Anyone that is running a apache vhost configuration will need 2 entries.

Both are identical except for the ServerName property.

One will need to be:    ServerName atv.plexconnect

and the other will need to be    ServerName trailers.apple.com
 
Was stuck with the "Trailers not available at this time" error but everything else looked normal. I had to really pay attention to the PlexConnect.log for intercept tid-bits to catch this.
 
Hope it helps!
Clad

Had everything running before the update Apple pushed down the other day. For whatever reason, I wanted to start fresh. Created a clean Ubuntu Server 12.04 VM in Parallels for the job. Only SSH server added. No Apache or DNS services.

If I launch PlexConnect manually everything works. When I use the script, PlexConnect loads, but the AppleTV gives me an error and doesn't connect.

I even tried the suggestions made by RivieraDude.

Any ideas?

Currently running

Server 12.04.3

Python 2.7.3

Prior to Apple's updates I had this all working wonderfully.  Yesterday I took the effort to fix correct PlexConnect to get it all running again on it's own and it will work now when I have Apache SSL disabled.  Right now I have the following added to my Settings.cfg file:

port_webserver = 8089
port_ssl = 443
certfile = /etc/plexconnect/trailers.pem

And an apache virtual host in /etc/apache2/conf.d/appletrailers.conf
 


ServerName trailers.apple.com

ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

ProxyPass / http://localhost:8089/
ProxyPassReverse / http://localhost:8089/

<Location />
    Order allow,deny
    Allow from all
</Location>

This works great, but I'd love to get SSL also redirected if at all possible...  Tried setting port_ssl to 8090 with this appended to appletrailers.conf, but it didn't work for me.  Any suggestions for how to do it right?  NB: Listen 443 and mod_ssl are present/enabled.



    ServerName trailers.apple.com

    SSLEngine on
    SSLCertificateFile /etc/plexconnect/trailers.cer
    SSLCertificateKeyFile /etc/plexconnect/trailers.key
    #SSLCertificateChainFile /etc/plexconnect/trailers.cer

    ProxyRequests Off
    ProxyPreserveHost On
    
        Order deny,allow
        Allow from all
    

    ProxyPass / https://localhost:8090/
    ProxyPassReverse / https://localhost:8090/

    
        Order allow,deny
        Allow from all
    


If I launch PlexConnect manually everything works. When I use the script, PlexConnect loads, but the AppleTV gives me an error and doesn't connect.


Any ideas?

No ideas just now but I can confirm that the new PlexConnect does not appear to work properly with the existing screen call on Ubuntu Server 12.04.

No ideas just now but I can confirm that the new PlexConnect does not appear to work properly with the existing screen call on Ubuntu Server 12.04.

Thanks, ReneV. At least I know I'm not crazy. :)