Skip to content

Instantly share code, notes, and snippets.

@sambanks
Created February 16, 2016 23:45
Show Gist options
  • Select an option

  • Save sambanks/c87a3d24055a5c41185e to your computer and use it in GitHub Desktop.

Select an option

Save sambanks/c87a3d24055a5c41185e to your computer and use it in GitHub Desktop.
PlexConnect Autostart /etc/init.d/plexconnect Script for Ubuntu 14.04
### BEGIN INIT INFO
# Provides: plexconnext
# Required-Start: plexmediaserver networking
# Required-Stop: plexmediaserver networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: PlexConnect
# Description: Init Script for PlexConnect Daemon
### END INIT INFO
. /lib/lsb/init-functions
NAME=PlexConnect
PIDFILE="/var/lib/plexmediaserver/plexconnect.pid"
DAEMON="/usr/local/lib/plexconnect/PlexConnect_daemon.py"
DAEMON_OPTS="--pidfile $PIDFILE"
DAEMON_USER="plex"
case $1 in
start)
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE "$DAEMON" "$NAME process" && status="0" || status="$?"
if [ $status = "0" ]; then
exit # Exit
fi
fi
log_daemon_msg "Starting the process" "$NAME"
if start-stop-daemon -c $DAEMON_USER -S -q -o --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS ; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
# Stop the daemon.
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE "$DAEMON" "$NAME process shut down" && status="0" || status="$?"
if [ "$status" = 0 ]; then
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
/bin/rm -rf $PIDFILE
fi
echo " * Stopped"
else
log_daemon_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" "$NAME process" && exit 0 || exit $?
else
log_daemon_msg "$NAME Process is not running"
log_end_msg 0
fi
;;
reload)
# Reload the process. Basically sending some signal to a daemon to reload
# it configurations.
if [ -e $PIDFILE ]; then
start-stop-daemon --stop --signal USR1 --quiet --pidfile $PIDFILE --name $NAME
log_success_msg "$NAME process reloaded successfully"
else
log_failure_msg "$PIDFILE does not exists"
fi
;;
*)
# For invalid arguments, print the usage message.
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment