I will be rebooting the system tonight so will see if plexconnect services start automatically… It’s annoying at the moment because as soon as I close session the services stop really wish could get this running as daemon
Alan, tallerthenyou's script above should work for you and it has been run and tested on Unbuntu. That would be the approach I would recommend you try first. While my script should be pretty close to working if it is not already working I can't test it on Ubuntu. tallerthanyou and I have different approaches to doing it, but either should work well.
If PlexConnect keeps shutting down each time you try to run it headless (as a daemon or using nohup etc) then I suspect you didn't fully comment out the code in the last part of tallerthanyou's instructions. This is the main difference between tallerthanyou's approach and mine. tallerthanyou's script is simpler and easier but requires code changes in PlexConnect.py. Mine doesn't need code changes to PlexConnect.py but it is more complex as it relies on using the 'screen' application to work.
@tallerthenyou I have just restarted my ubuntu machine there and can confirm that plexconnect services started automatically on startup thanks for your help :)
@wilsoncd2 I had slight problems with the start-stop-daemon part of your script on Ubuntu 12.04 server; the following variant seems to work. It goes in /etc/init.d/plexconnect (owned by root:root, with 755 permissions).
EDIT: there's (still) no need to edit any PlexConnect code for this to work.
To have it run automatically at startup, run the following when all is set up and tested
sudo update-rc.d plexconnect defaults
#!/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 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 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 ;; 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}" exit 2 ;; esac
@wilsoncd2 I had slight problems with the start-stop-daemon part of your script on Ubuntu 12.04 server; the following variant seems to work. It goes in /etc/init.d/plexconnect (owned by root:root, with 755 permissions).
@ReneV thanks for testing and fixing the script for Ubuntu. Hopefully it will be useful for others as well.
@ReneV thanks for testing and fixing the script for Ubuntu. Hopefully it will be useful for others as well.
Thanks for the updated post wilsoncd2, one change though, to start the service in ubuntu, you need to issue "sudo service plexconnect start", not "sudo start plexconnect" as you mentioned in your post. Other than that looks great! :)
Thanks for the updated post wilsoncd2, one change though, to start the service in ubuntu, you need to issue "sudo service plexconnect start", not "sudo start plexconnect" as you mentioned in your post. Other than that looks great! :)
@"Maxwell Smart" thank you for that, I updated my post.
Lastly I had to comment out the following lines from PlexConnect.py to prevent it from exiting imediatly:
try:
key = raw_input()
except KeyboardInterrupt:
dprint('PlexConnect', 0, "^C received.")
finally:
dprint('PlexConnect', 0, "Shutting down.")
cmd_DNSServer.put('shutdown')
cmd_WebServer.put('shutdown')
p_DNSServer.join()
p_WebServer.join()This has been working for me, but I'd love to hear if someone else has come up with a cleaner solution
In the most recent PlexConnect.py, uploaded 3 days ago, it no longer has this code. Therefore, I have no idea what to comment out now. I have gotten this far in the instructions under Ubuntu without problems but now cannot get the script to stop exiting automatically. In other words, I've got it to start every time at boot but it then quits. I'm a complete newb at Linux but any directions you can provide would be greatly appreciated. Thanks.
If you use wilsoncd2's instructions there is no need to modify the PlexConnect at all. That said, the reason that was removed is because the dev's are working on getting proper daemon / process support enabled, so I wouldn't be surprised to see an update soon with this functionality properly implemented so we no longer need to use the "screen" application.
Unfortunately I do not have a Unbuntu system to use to modify the script on. I can make a guess from memory but that is as good as I can do right now. Try this modified version. But remember you must have the application 'screen' installed for this script to work. Also please check and modify (if neccessary) the following.
- the import statement ". /lib/lsb/init-functions" (make sure that /lib/lsb/init-functions is a file that exists). Otherwise you will need to correct the path to adjust for ubuntus location.
- DAEMON_OPTS="-S PlexConnect -d -m /var/lib/PlexConnect/PlexConnect.py" (make sure the path is correct to your PlexConnect.py, or update it to the correct path).
I have modified this from memory so it is very likely that it will not work. Put this in to the file /etc/init.d/plexconnect and see if it works.
#!/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 INFOUsing 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>&1If the status is SUCCESS then don’t need to start again.
if [ $? = “0” ]; then
log_success_msg “Starting the process $NAME”
exit # Exit
fi
fiStart the daemon.
#log_daemon_msg “Starting the process” “$NAME”
Start the daemon with the help of start-stop-daemon
Log the message appropriately
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
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
;;
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}”
exit 2
;;
esac
Ubuntu 13.04 errors on this line
status_of_proc -p $PIDFILE "$DAEMON $DAEMON_OPTS" "$NAME process" && status="0" || status="$?"
with "cannot chdir() to "-m"
Any ideas? I took put the command line that starts PlexConnect in a screen session into /etc/rc.local since it does what I want. It would be nice to get your script to work.
PlexConnect now has proper daemon code for Linux so this thread is out of date.
usage:
cd /PlexConnect
sudo ./PlexConnect_daemon.bash start
sudo ./PlexConnect_daemon.bash status
sudo ./PlexConnect_daemon.bash stop
Does any1 have an idea how to use those new scripts to automatically start them when booting?
Ok managed to figure it out myself, just created a symlink to add it to autostart :)
I have PlexConnect running on boot, but it's not the most elegant solution:
/etc/init/plexconnect.conf
# plexconnect - service job filedescription “PlexConnect”
author “http://www.plexapp.com/”Start the media server after network and filesystem
Otherwise this lead to a unresponsive server
start on filesystem and net-device-up IFACE!=lo
When to stop the service
stop on runlevel [016]
Automatically restart process if crashed
respawn
Sets nice and ionice level for job
nice -5
What to execute
script
sleep 10
start-stop-daemon --start --exec /usr/sbin/start_plexconnect
end script
I added the "sleep 10" to ensure that PMS had started so PlexConnect would find it. I bet there's a better way to do that, but I couldn't find it.
/usr/sbin/start_plexconnect
#!/bin/bashPLEXCONNECT_SRC=/home/john/src/PlexConnect
PLEXCONNECT_LOG=/tmp/plexconnect.logi=0
while [ -r “$PLEXCONNECT_LOG-$i” ]; do
(( i++ ))
done(cd $PLEXCONNECT_SRC; ./PlexConnect.py > $PLEXCONNECT_LOG-$i)
You'll obviously have to change PLEXCONNECT_SRC to reflect where you have your PlexConnect source folder located.
Lastly I had to comment out the following lines from PlexConnect.py to prevent it from exiting imediatly:
try: key = raw_input() except KeyboardInterrupt: dprint('PlexConnect', 0, "^C received.")finally: dprint('PlexConnect', 0, "Shutting down.") cmd_DNSServer.put('shutdown') cmd_WebServer.put('shutdown') p_DNSServer.join() p_WebServer.join()
This has been working for me, but I'd love to hear if someone else has come up with a cleaner solution
Sorry to revive an old post, but thought it better than a new thread.
This worked perfectly for me. :D
Steps 1 & 2 worked a treat. There was no need to comment out step 3. PlexConnect works perfectly upon every Ubuntu 14.04.2 headless server boot :)
Please also remember to change permissions to 0644 for plexconnect.conf and 0755 start_plexconnect ;)
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.