SABnzbd 0.7.16 and Fedora 20 updated init scripts

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
domo
Newbie
Newbie
Posts: 1
Joined: December 1st, 2013, 10:23 am

SABnzbd 0.7.16 and Fedora 20 updated init scripts

Post by domo »

With fedora 20 launching in 9 days, I've gone though the SABnzbd fedora init scripts and updated them.

Thanks to diedjee for the original scripts. This will correct the nc -z bug introduced after they changed the deployed netcat version in fedora 19 and updates the shutdown method to use the new SABnzbd api.

/etc/sysconfig/SABnzbd

Code: Select all

# SABnzbd service configuration

#run SABnzbd as
sabuser=user

#modify if SABnzbd config file is somewhere else for some reason
config="/home/${sabuser}/.sabnzbd/sabnzbd.ini"

#API key (can be found in the above config file)

apikey=$(cat "$config" | grep -E "^api_key =" | awk '{print $3}')

#gui address, eg: ${protocol}://${host}:${port}/sabznbd/
protocol=http
host=127.0.0.1
port=8080

#use nice, ionice, taskset to start SABnzbd
nicecmd=
#  example: nicecmd="nice -n 19 ionice -c3"
Note the removal of the password and username arguments. They are no longer required with the new API in SABnzbd 0.7.16.

/etc/init.d/SABnzbd

Code: Select all

#!/bin/sh

# chkconfig: - 20 80
# description: SABnzbd

exec="/usr/share/SABnzbd/SABnzbd.py"
prog="SABnzbd"

if [ -f /etc/sysconfig/$prog ]; then
   . /etc/sysconfig/$prog
fi

if [ ! -n "$sabuser" -o ! -n "$apikey" -o ! -n "$protocol" -o ! -n  "$host"  -o ! -n "$port" ]; then
  echo "Please configure /etc/sysconfig/$prog first."
  [ ! -n "$sabuser"  ] && echo -n " sabuser"
  [ ! -n "$apikey"   ] && echo -n " apikey"
  [ ! -n "$protocol" ] && echo -n " protocol"
  [ ! -n "$host"     ] && echo -n " host"
  [ ! -n "$port"     ] && echo -n " port"
  echo " variable(s) undefined"
  exit 1
fi

if [ ! -f "$config" ]; then
  echo "Can't find $config."
  echo "Please run SABnzbd as $sabuser manually to configure it first."
  exit 1
fi
            
# Source function library.
. /etc/rc.d/init.d/functions

start() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6

    echo -n $"Starting $prog: "
    # if not running, start it up here, usually something like "daemon $exec"
    daemon --user=$sabuser $nicecmd $exec -d -f $config
    retval=$?
    echo
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
   shutdownurl="${protocol}://${host}:${port}/sabnzbd/api?mode=shutdown&apikey=${apikey}"

    /usr/bin/wget -q --delete-after --no-check-certificate "$shutdownurl"

echo "fetched $shutdownurl"

    for sleepval in 1s 5s 10s 20s;do
   sleep $sleepval
        rh_status_q
        ret=$?
   if [ $ret -ne 0 ];then
       echo_success
       echo
       return 0
   fi
    done
    echo_failure
    return 1
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

#Check whether the server is listening on $host:$port
#An exit value of 0 means: LISTENING
#Another value means: NOT LISTENING
rh_status() {
    # run checks to determine if the service is running or use generic status
    nbports=$(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ":'$port'"' | wc -l)

    if [ $nbports -ne 0 ];then
   pid=`ps -fu $sabuser | grep -v grep | grep SABnzbd.py | awk '{print $2}'`;
   echo "$prog (pid $pid) is running...";
   ret=0;
    else
   echo "$prog is stopped"
   ret=1;
    fi
    echo "rh_status return=$ret"
    return $ret;

}

#Same definition as for rh_status but query version (no output)
rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
echo "STOP SWITCH"
        rh_status
        rh_status_q || echo "TEST 1"
        rh_status_q && echo "TEST 2"
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        $1
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?
Comments, concerns or additions, just paste them below.
bryanb
Newbie
Newbie
Posts: 1
Joined: December 28th, 2013, 10:59 pm

Re: SABnzbd 0.7.16 and Fedora 20 updated init scripts

Post by bryanb »

Thanks, I've upgraded to F20, and this seems to have fixed some problems I had.

I initially set it up like this:
http://wiki.sabnzbd.org/install-fedora-repo

which worked on F19 just fine. On F20, I couldn't stop the service, either from the new changes, or something I screwed up.

I muddled through, and eventually found this article, and somehow, everything seems fine now.
Hansvon
Jr. Member
Jr. Member
Posts: 81
Joined: April 28th, 2010, 2:18 am

Re: SABnzbd 0.7.16 and Fedora 20 updated init scripts

Post by Hansvon »

Hey,
Sorry for the very late answer. I've just updated the RPM. Now, for fedora>=19, it uses systemd directly (no more init scripts), which is the recommended way to do since a few Fedora releases Have a try. For me, it works perfectly.
martdj
Newbie
Newbie
Posts: 2
Joined: February 9th, 2014, 2:06 pm

Re: SABnzbd 0.7.16 and Fedora 20 updated init scripts

Post by martdj »

Hi Hansvon,
I installed your package, but can't find any .service file and subsequently can't start SABnzbd with systemctl. What am I missing?
Hansvon
Jr. Member
Jr. Member
Posts: 81
Joined: April 28th, 2010, 2:18 am

Re: SABnzbd 0.7.16 and Fedora 20 updated init scripts

Post by Hansvon »

Hi,
Are you really using 0.7.16-3 on Fedora 19 or 20? (rpm -q SABnzbd) For Fedora <=18, which are not supported anymore, I left the init.d script.

The service file should be available at /usr/lib/systemd/system/SABnzbd@.service
And you start it with systemctl start SABnzbd@john.service where john is the username under which sabnzbd should run.
martdj
Newbie
Newbie
Posts: 2
Joined: February 9th, 2014, 2:06 pm

Re: SABnzbd 0.7.16 and Fedora 20 updated init scripts

Post by martdj »

Thanks for your quick reply Hansvon. I did a yum reinstall SABnzbd and that solved the problem
liquefry
Newbie
Newbie
Posts: 1
Joined: March 12th, 2014, 4:23 pm

Re: SABnzbd 0.7.16 and Fedora 20 updated init scripts

Post by liquefry »

Hi Hansvon, thanks for your work on the Fedora repo!
And you start it with systemctl start SABnzbd@john.service where john is the username under which sabnzbd should run.
Can you please add this to the installation page, or a help page somewhere? I finally updated to the latest version today and couldn't figure out how to start the service until I found this thread. Also, to start up automatically I added "systemctl enable SABnzbd@john.service" where john is my sab user. Is this correct?
diedjee
Newbie
Newbie
Posts: 9
Joined: December 22nd, 2010, 1:33 pm

Re: SABnzbd 0.7.16 and Fedora 20 updated init scripts

Post by diedjee »

That is correct, liquefry.

Code: Select all

systemctl enable SABnzbd@john.service
will install the service.

You can see the status of the process using

Code: Select all

systemctl status SABnzbd@john.service
.

Fedora also has a GUI for configuring your services called Service configuration.
The binary is named

Code: Select all

serviceconf
.
Post Reply