Background Story
I have been running Plexconnect as a service through sysvinit (/etc/init.d/) as explained in this post:
https://forums.plex.tv/discussion/156534/install-on-ubuntu-server#latest
After each reboot i still had to restart the service because it would start as
Active (exited)
I belive that's because in order to get the init file to work now one would have to remove plexmediaserver
# Required-Start: networking **plexmediaserver**
from /etc/init.d/plexconnect for it to work properly. This is because now Ubuntu uses systemd, naturally Plex Media Server now comes with a unit file (systemd) . So what we need now is a systemd unit file for plexconnect. Ill follow most of the old steps as i have no intention of reinventing the wheel.
It's also worth mentioning if you have your init.d script running without any issues, you dont need to follow this guide.
Removing the old sysvinit script (/etc/init.d/plexconnect)
(If you never followed the old guide you obviously dont have to do this)
Stop the server:
sudo service plexconnect stop
Backup your current script in case our new unit file does not work for you!
sudo mv /etc/init.d/plexconnect /etc/init.d/plexconnect.bak
Remove the script from rc.d
sudo update-rc.d plexconnect remove
Now you are ready to proceed.
If for some reason our new unit file does not work:
sudo mv /etc/init.d/plexconnect.bak /etc/init.d/plexconnect
sudo update-rc.d plexconnect defaults
How to Install
Full installation documentation can be found here:
https://github.com/iBaa/PlexConnect/wiki/Install-Guide-Linux
We start by downloading Plexconnect, moving it to a more suitable location, adding some sql keys & certificates for the appletv and then moving the certificates. Do this commands one at a time (Trippel click on each line and copy) .
(If you allready have Plexconnect you can skip this step)
wget https://github.com/iBaa/PlexConnect/archive/master.zip
unzip master.zip
sudo mv PlexConnect-master/ /usr/local/lib/PlexConnect
openssl req -new -nodes -newkey rsa:2048 -out ./trailers.pem -keyout ./trailers.key -x509 -days 7300 -subj "/C=US/CN=trailers.apple.com"
openssl x509 -in ./trailers.pem -outform der -out ./trailers.cer && cat ./trailers.key >> ./trailers.pem
mv trailers.* /usr/local/lib/PlexConnect/assets/certificates/
Now we are going to make the unit file for the startup process:
(If you have installed Plexconnect somewhere else than "/usr/local/lib/PlexConnect" you need to replace this path with yours in every step its mentioned)
sudo nano /etc/systemd/system/plexconnect.service
Paste the following:
[Unit]
Description=Plexconnect
After=plexmediaserver.service
[Service]
Type=simple
ExecStart=/usr/bin/python /usr/local/lib/PlexConnect/PlexConnect.py
User=root
Group=root
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
[Install]
WantedBy=multi-user.target
Exit and save with: "Ctrl-x, Y, Enter"
Now we need to set the right permissions for our unit file:
sudo chmod 644 /etc/systemd/system/plexconnect.service
Now we update systemd:
sudo systemctl daemon-reload
Finally we add our unit file:
sudo systemctl enable plexconnect.service
Now our service is ready and we can start it with:
sudo systemctl start plexconnect.service
You can check your service status with:
sudo systemctl status plexconnect.service
or:
sudo service plexconnect status
Finally, how to setup your apple-tv:
https://github.com/iBaa/PlexConnect/wiki/Install-Guide
Sources:
http://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/
https://gist.github.com/tstellanova/7323116
https://forums.plex.tv/discussion/156534/install-on-ubuntu-server#latest
https://wiki.ubuntu.com/SystemdForUpstartUsers