Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.79 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # chkconfig: - 20 80
  4. # description: SABnzbd
  5.  
  6. exec="/opt/SABnzbd/SABnzbd.py"
  7. prog="SABnzbd"
  8.  
  9. if [ -f /etc/sysconfig/$prog ]; then
  10.         . /etc/sysconfig/$prog
  11. fi
  12.  
  13. if [ ! -n "$sabuser" -o ! -n "$apikey" -o ! -n "$protocol" -o ! -n  "$host"  -o ! -n "$port" ]; then
  14.   echo "Please configure /etc/sysconfig/$prog first."
  15.   [ ! -n "$sabuser"  ] && echo -n " sabuser"
  16.   [ ! -n "$apikey"   ] && echo -n " apikey"
  17.   [ ! -n "$protocol" ] && echo -n " protocol"
  18.   [ ! -n "$host"     ] && echo -n " host"
  19.   [ ! -n "$port"     ] && echo -n " port"
  20.   echo " variable(s) undefined"
  21.   exit 1
  22. fi
  23.  
  24. if [ ! -f "$config" ]; then
  25.   echo "Can't find $config."
  26.   echo "Please run SABnzbd as $sabuser manually to configure it first."
  27.   exit 1
  28. fi
  29.                    
  30.  
  31. # Source function library.
  32. . /etc/rc.d/init.d/functions
  33.  
  34. start() {
  35.     [ -x $exec ] || exit 5
  36.     [ -f $config ] || exit 6
  37.  
  38.     echo -n $"Starting $prog: "
  39.     # if not running, start it up here, usually something like "daemon $exec"
  40.     daemon --user=$sabuser $nicecmd $exec -d -f $config
  41.     retval=$?
  42.     echo
  43.     return $retval
  44. }
  45.  
  46. stop() {
  47.     echo -n $"Stopping $prog: "
  48.     if [ -n "$username" ]; then
  49.     /usr/bin/wget -q --delete-after --no-check-certificate "${protocol}://${host}:${port}/sabnzbd/api?mode=shutdown&ma_username=${username}&ma_password=${password}&apikey=${apikey}"
  50.     else
  51.     /usr/bin/wget -q --delete-after --no-check-certificate "${protocol}://${host}:${port}/sabnzbd/api?mode=shutdown&apikey=${apikey}"
  52.     fi
  53.    
  54.     for sleepval in 1s 5s 10s 20s;do
  55.     sleep $sleepval
  56.     if [ ! `rh_status_q` ];then
  57.         echo_success
  58.         echo
  59.         return 0
  60.     fi
  61.     done
  62.     echo_failure
  63.     return 1
  64. }
  65.  
  66. restart() {
  67.     stop
  68.     start
  69. }
  70.  
  71. reload() {
  72.     restart
  73. }
  74.  
  75. force_reload() {
  76.     restart
  77. }
  78.  
  79. rh_status() {
  80.     # run checks to determine if the service is running or use generic status
  81.  
  82.     /usr/bin/nc -z $host $port &> /dev/null
  83.     retval=$?
  84.  
  85.     if [ $retval -eq 0 ];then
  86.     pid=`ps -fu $sabuser | grep -v grep | grep SABnzbd.py | awk '{print $2}'`
  87.     echo "$prog (pid $pid) is running..."
  88.     return $retval
  89.     else
  90.     echo "$prog is stopped"
  91.     return $retval
  92.     fi
  93.  
  94. }
  95.  
  96. rh_status_q() {
  97.     rh_status >/dev/null 2>&1
  98. }
  99.  
  100.  
  101. case "$1" in
  102.     start)
  103.         rh_status_q && exit 0
  104.         $1
  105.         ;;
  106.     stop)
  107.         rh_status_q || exit 0
  108.         $1
  109.         ;;
  110.     restart)
  111.         $1
  112.         ;;
  113.     reload)
  114.         rh_status_q || exit 7
  115.         $1
  116.         ;;
  117.     force-reload)
  118.         force_reload
  119.         ;;
  120.     status)
  121.         rh_status
  122.         ;;
  123.     condrestart|try-restart)
  124.         rh_status_q || exit 0
  125.         restart
  126.         ;;
  127.     *)
  128.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  129.         exit 2
  130. esac
  131. exit $?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement