QuidsUp - Scripts - SickBeard Init Script

SickBeard Init Script

Init script to run the TV PVR downloader SickBeard at Bootup Time.
For use with Ubuntu based systems. See How to Install & Configure SickBeard for full install guide.

Init Script:
#! /bin/sh
### BEGIN INIT INFO
# Provides:          sickbeard
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start sickbeard at boot time
# Description:       Start sickbeard
### END INIT INFO

#Author              QuidsUp
#Last Edited	     12 Dec 2013

#Required -- To be changed!
USER=you             #Set Ubuntu or Linux Mint username here.
APPPath=/home/you/SickBeard/
PIDFile=/home/you/.sickbeard.pid

set -e

case "$1" in
  start)
    echo "Starting SickBeard"
    if (test -f $PIDFile); then
      echo "Removing old SickBeard PID File"
      rm $PIDFile
    fi
    start-stop-daemon -v --chdir $APPPath --chuid $USER --start \
     --pidfile $PIDFile --exec /usr/bin/python -- SickBeard.py --daemon --pidfile=$PIDFile
  ;;

  stop)
    echo "Stopping SickBeard"
    start-stop-daemon -v --stop --chuid $USER --pidfile $PIDFile
    sleep 6s
  ;;

  restart|force-reload)
    echo "Stopping SickBeard for Restart"
    start-stop-daemon --stop --chuid $USER --pidfile $PIDFile
    echo "Stop Command Issued. Waiting for SickBeard to Shutdown"
    sleep 15s
    echo "Restarting SickBeard"
    start-stop-daemon --chdir $APPPath --chuid $USER --start \
     --pidfile $PIDFile --exec /usr/bin/python -- SickBeard.py --daemon --pidfile=$PIDFile
  ;;

  status)
    echo "Checking Status of SickBeard"
    if (test -f $PIDFile); then
      PIDVal=$(head -1 $PIDFile)
      if [ -e /proc/$PIDVal ]; then
        echo -n "SickBeard Running on Process ID: "
        echo $PIDVal
        echo
        ps -H $PIDVal
      else
        echo "SickBeard Not Running"
	exit 1
      fi
    else
      echo "No PID File found for SickBeard"
    fi
  ;;

  *)
     echo "Usage: sickbeard {start|stop|restart|force-reload|status}" >&2
     exit 1
   ;;
esac

exit 0