Trinket

sickbeard

Mar 3rd, 2013
24
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. #
  3. ### BEGIN INIT INFO
  4. # Provides:          sickbeard
  5. # Required-Start:    $local_fs $network $remote_fs
  6. # Required-Stop:     $local_fs $network $remote_fs
  7. # Should-Start:      $NetworkManager
  8. # Should-Stop:       $NetworkManager
  9. # Default-Start:     2 3 4 5
  10. # Default-Stop:      0 1 6
  11. # Short-Description: starts instance of Sick Beard
  12. # Description:       starts instance of Sick Beard using start-stop-daemon
  13. ### END INIT INFO
  14.  
  15. # Source SickBeard configuration
  16. if [ -f /etc/default/sickbeard ]; then
  17.     . /etc/default/sickbeard
  18. else
  19.     echo "/etc/default/sickbeard not found using default settings.";
  20. fi
  21.  
  22. # Script name
  23. NAME=sickbeard
  24.  
  25. # App name
  26. DESC=SickBeard
  27.  
  28. ## Don't edit this file
  29. ## Edit user configuation in /etc/default/sickbeard to change
  30. ##
  31. ## SB_USER=         #$RUN_AS, username to run sickbeard under, the default is sickbeard
  32. ## SB_HOME=         #$APP_PATH, the location of SickBeard.py, the default is /opt/sickbeard
  33. ## SB_DATA=         #$DATA_DIR, the location of sickbeard.db, cache, logs, the default is /opt/sickbeard
  34. ## SB_PIDFILE=      #$PID_FILE, the location of sickbeard.pid, the default is /var/run/sickbeard/sickbeard.pid
  35. ## PYTHON_BIN=      #$DAEMON, the location of the python binary, the default is /usr/bin/python
  36. ## SB_OPTS=         #$EXTRA_DAEMON_OPTS, extra cli option for sickbeard, i.e. " --config=/home/sickbeard/config.ini"
  37. ## SSD_OPTS=        #$EXTRA_SSD_OPTS, extra start-stop-daemon option like " --group=users"
  38. ##
  39. ## EXAMPLE if want to run as different user
  40. ## add SB_USER=username to /etc/default/sickbeard
  41. ## otherwise default sickbeard is used
  42.  
  43. ## The defaults
  44. # Run as username
  45. USER=${USER}
  46. GROUP=${GROUP}
  47. # Path to app SB_HOME=path_to_app_SickBeard.py
  48. APP_PATH=${SB_HOME-/opt/sickbeard}
  49.  
  50. # Data directory where sickbeard.db, cache and logs are stored
  51. DATA_DIR=${SB_DATA-/opt/sickbeard}
  52.  
  53. # Path to store PID file
  54. PID_FILE=${SB_PIDFILE-/var/run/sickbeard/sickbeard.pid}
  55.  
  56. # path to python bin
  57. DAEMON=${PYTHON_BIN-/usr/bin/python}
  58.  
  59. # Extra daemon option like: SB_OPTS=" --config=/home/sickbeard/config.ini"
  60. EXTRA_DAEMON_OPTS=${SB_OPTS-}
  61.  
  62. # Extra start-stop-daemon option like START_OPTS=" --group=users"
  63. EXTRA_SSD_OPTS=${SSD_OPTS-}
  64. ##
  65.  
  66. PID_PATH=`dirname $PID_FILE`
  67. DAEMON_OPTS=" SickBeard.py -q --daemon --nolaunch --pidfile=${PID_FILE} --datadir=${DATA_DIR} ${EXTRA_DAEMON_OPTS}"
  68.  
  69. ##
  70.  
  71. test -x $DAEMON || exit 0
  72.  
  73. set -e
  74.  
  75. # Create PID directory if not exist and ensure the SickBeard user can write to it
  76. if [ ! -d $PID_PATH ]; then
  77.     mkdir -p $PID_PATH
  78.     chown $USER:$GROUP $PID_PATH
  79. fi
  80.  
  81. if [ ! -d $DATA_DIR ]; then
  82.     mkdir -p $DATA_DIR
  83.     chown $USER:$GROUP $DATA_DIR
  84. fi
  85.  
  86. if [ -e $PID_FILE ]; then
  87.     PID=`cat $PID_FILE`
  88.     if ! kill -0 $PID > /dev/null 2>&1; then
  89.         echo "Removing stale $PID_FILE"
  90.         rm $PID_FILE
  91.     fi
  92. fi
  93.  
  94. case "$1" in
  95.     start)
  96.         echo "Starting $DESC"
  97.         start-stop-daemon -N 10 -d $APP_PATH -c $USER:$GROUP $EXTRA_SSD_OPTS --start --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
  98.         ;;
  99.     stop)
  100.         echo "Stopping $DESC"
  101.         start-stop-daemon --stop --pidfile $PID_FILE --retry 15
  102.         ;;
  103.  
  104.     restart|force-reload)
  105.         echo "Restarting $DESC"
  106.         start-stop-daemon --stop --pidfile $PID_FILE --retry 15
  107.         start-stop-daemon -N 10 -d $APP_PATH -c $USER:$GROUP $EXTRA_SSD_OPTS --start --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
  108.         ;;
  109.     *)
  110.         N=/etc/init.d/$NAME
  111.         echo "Usage: $N {start|stop|restart|force-reload}" >&2
  112.         exit 1
  113.         ;;
  114. esac
  115.  
  116. exit 0
RAW Paste Data