Auto staring PlexConnect on CentOS

With AppleTV 4 we are getting a native Plex client, but some people are still using PlexConnect as it works, and is very stable.

Some time ago I create a very simple init script to start, stop and update PlexConnect:
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: PlexConnect
# Required-Start: $network $local_fs
# Required-Stop: $local_fs
# Default-Start: 3 5
# Default-Stop: 0 1 6
# Short-Description: starts PlexConnect
# Description: starts PlexConnect
### END INIT INFO

# Source function library.
. /etc/init.d/functions
. /lib/lsb/init-functions

if [ ! -f /etc/sysconfig/PlexConnect ] ; then
echo "/etc/sysconfig/PlexConnect missing!"
exit 0;
fi

. /etc/sysconfig/PlexConnect

## Variables
#USER=root
#PROG=PlexConnect
#LOCKFILE=/var/lock/subsys/$PROG
#HOMEDIR=/srv/$PROG
#PIDFILE=/var/run/$PROG.pid
#PYTHON=/usr/local/bin/python2.7

start() {
# Check for already running
if status $PROG > /dev/null ; then
echo "$PROG (pid `pidofproc -p $PIDFILE $PROG`) is running..."
exit 0;
fi
# Start daemon.
echo -n "Starting $PROG: "
cd $HOMEDIR
screen -dmS $PROG $PYTHON $PROG.py $OPTIONS
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
PID=`screen -ls | grep PlexConnect | awk -F'.' '{print $1}' | tr -d '\t'`
echo $PID > $PIDFILE
log_success_msg ""
else
log_failure_msg ""
fi
[ $RETVAL -eq 0 ] && touch $LOCKFILE
return $RETVAL
}

stop() {
echo -n $"Shutting down $PROG: "
killproc -p $PIDFILE $PYTHON
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
log_success_msg ""
else
log_failure_msg ""
fi
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
return $RETVAL
}

update() {
echo "Updating $PROG"
cd $HOMEDIR
git pull
}


# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $PROG
;;
restart|force-reload)
stop
start
;;
try-restart|condrestart)
if status $PROG > /dev/null; then
stop
start
fi
;;
update)
RESTART="FALSE"
if status $PROG > /dev/null; then
stop
RESTART="TRUE"
fi
update
if [ "$RESTART" = "TRUE" ] ; then
start
fi
;;
reload)
exit 3
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload|update}"
exit 2
esac

It will require /etc/sysconfig/PlexConnect:
# PlexConnect Settings
USER=root
PROG=PlexConnect
LOCKFILE=/var/lock/subsys/$PROG
HOMEDIR=/srv/$PROG
PIDFILE=/var/run/$PROG.pid
PYTHON=/usr/local/bin/python2.7
OPTIONS=""

(PlexConnect like Python 2.7)

Could probably be made smarter, but it works for me.

Comments

Popular posts from this blog

Apple AirPort Express and Digital Jitter..

EIZO Colornavigator - Data Access Error

Using Borg backup across SSH with sshkeys