0

I have installed a python script called "plexconnect" which is basicly a script to trick my apple tv3 in to looking elsewhere for its trailers. Source: https://github.com/iBaa/PlexConnect

Then i made an init script. Source: https://forums.plex.tv/discussion/156534/install-on-ubuntu-server

The (minor) problem i have with this deamon is after a reboot the service allways start as active (exited):

● plexconnect.service - LSB: This is the Plex Connect daemon
   Loaded: loaded (/etc/init.d/plexconnect; bad; vendor preset: enabled)
   Active: active (exited) since sø. 2016-03-27 14:29:27 CEST; 1min 14s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1043 ExecStart=/etc/init.d/plexconnect start (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 512)


mars 27 14:29:26 lenox2 systemd[1]: Starting LSB: This is the Plex Connect daemon...
mars 27 14:29:27 lenox2 plexconnect[1043]:  * Starting the process PlexConnect
mars 27 14:29:27 lenox2 systemd[1]: Started LSB: This is the Plex Connect daemon.

After i restart the service it works fine active (running):

● plexconnect.service - LSB: This is the Plex Connect daemon
   Loaded: loaded (/etc/init.d/plexconnect; bad; vendor preset: enabled)
   Active: active (running) since sø. 2016-03-27 14:31:09 CEST; 1s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1911 ExecStop=/etc/init.d/plexconnect stop (code=exited, status=0/SUCCESS)
  Process: 1921 ExecStart=/etc/init.d/plexconnect start (code=exited, status=0/SUCCESS)
    Tasks: 6 (limit: 512)
   CGroup: /system.slice/plexconnect.service
           ├─1930 /usr/bin/SCREEN -S PlexConnect -d -m /usr/local/lib/PlexConnect/PlexConnect.py
           ├─1933 python /usr/local/lib/PlexConnect/PlexConnect.py
           ├─1936 python /usr/local/lib/PlexConnect/PlexConnect.py
           ├─1940 python /usr/local/lib/PlexConnect/PlexConnect.py
           ├─1942 python /usr/local/lib/PlexConnect/PlexConnect.py
           └─1944 python /usr/local/lib/PlexConnect/PlexConnect.py


mars 27 14:31:09 lenox2 systemd[1]: Starting LSB: This is the Plex Connect daemon...
mars 27 14:31:09 lenox2 plexconnect[1921]:  * Starting the process PlexConnect
mars 27 14:31:09 lenox2 systemd[1]: Started LSB: This is the Plex Connect daemon.

I have tried to stop the plexmediaserver and restart the plexconnect to se if theres a problem with dependencies but it runs fine without plexmediaserver. I have also tried to add plexmediaserver as a Required-Start to the init script:

#Required-Start:  networking plexmediaserver

then:

sudo update-rc.d plexconnect defaults
insserv: Service plexmediaserver has to be enabled to start service plexconnect
insserv: exiting now!

Its clear Im in over my head here and need help. The only clue i have now is the extra python lines at the bottom service status after a restart. Could it be python need to be a Required-Start?

Complete code for init script:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          plexconnect
# Required-Start:    networking
# Required-Stop:     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 /usr/local/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"||exit5

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"&&exit0||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}"
  exit2
  ;;
esac

EDIT:

I´ve been looking at converting the sysvinit (plexconnect) to an Upstart.conf since plexconnect is an Upstart.conf but then i found out that ubuntu now uses systemd.

The problem i have now is that for some reason plexmediaserver runs as an Upstart and when i try to make an Upstart plexconnect.conf this happens:

initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused

So now i´m even more confused... How could plexmediaplayer get to be an Upstart service if 16.04 does not allow me to update Upstart? (Installed via the Ubuntu package).

1
  • Delete please... There was no one asnwer for this.
    – Izzno
    Mar 30, 2016 at 16:38

1 Answer 1

0

The main issue was Plexmediaserver was using Upstart/systemD so the init script failes.

More info in this guide I made: http://forums.plex.tv/discussion/213637/ubuntu-15-debian-8-raspbian-jessie-arch-or-based-autostart

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .