Trinket

sabnzbd

Mar 3rd, 2013
18
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides: sabnzbd
  5. # Required-Start:
  6. # Required-Stop:
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: starts instance of SABnzbd
  10. # Description: starts instance of SABnzbd using start-stop-daemon
  11. ### END INIT INFO
  12.  
  13. if [[ ${EUID} -ne "0" ]]; then
  14. echo "You must be root to run this script..."
  15. exit 1;
  16. fi
  17.  
  18. function get_pid {
  19. PID=$(ps aux | grep -v grep | grep SABnzbd.py | awk '{print $2;}')
  20. [[ -n ${PID} ]] && echo "${PID}" || echo "0"
  21. }
  22.  
  23. function check_and_kill {
  24. PID=$(get_pid)
  25. if [[ "0" -ne ${PID} ]]; then
  26. echo "::Running SABnzbd found (${PID}), killing..."
  27. kill $PID
  28. fi
  29. }
  30.  
  31. NAME=sabnzbd
  32.  
  33. USER=sabnzbd
  34. GROUP=download
  35.  
  36. PID_FILE=/var/sabnzbd/sabnzbd.pid
  37.  
  38. SABNZBD_HOME=/usr/local/download/sabnzbd
  39.  
  40. SABNZBD_OPTS="--daemon -f /var/sabnzbd/sabnzbd.ini"
  41. SABNZBD_BIN=${SABNZBD_HOME}/SABnzbd.py
  42.  
  43. SABNZBD_START="start-stop-daemon -N 10 -I best-effort:6 --start --quiet --chuid ${USER}:${GROUP} --exec ${SABNZBD_BIN} -- ${SABNZBD_OPTS}"
  44.  
  45. case "$1" in
  46. start)
  47. echo "Starting daemon: ${NAME}"
  48. [[ $(get_pid) -eq "0" ]] && $SABNZBD_START || echo "SABnzbd is already running..."
  49. ;;
  50. stop)
  51. echo "Stopping daemon: ${NAME}"
  52. check_and_kill
  53. ;;
  54. restart)
  55. echo "Restarting daemon: ${NAME}"
  56. check_and_kill
  57. $SABNZBD_START
  58. ;;
  59. *)
  60. echo "Usage: ${NAME} (start|stop|restart)"
  61. ;;
  62. esac
  63.  
  64. exit 0
RAW Paste Data