Skip to content

Instantly share code, notes, and snippets.

@stuwilli
Forked from joshenders/sabnzbdplus.default
Created June 21, 2013 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuwilli/5829453 to your computer and use it in GitHub Desktop.
Save stuwilli/5829453 to your computer and use it in GitHub Desktop.
# This file is sourced by /etc/init.d/sabnzbdplus
#
# When SABnzbd+ is started using the init script, the
# --daemon option is always used, and the program is
# started under the account of $USER, as set below.
#
# Each setting is marked either "required" or "optional";
# leaving any required setting unconfigured will cause
# the service to not start.
# [required] user or uid of account to run the program as:
USER=sabnzbd
# [optional] full path to the configuration file of your choice;
# otherwise, the default location (in $USER's home
# directory) is used:
CONFIG=/usr/src/sabnzbd/sabnzbd.ini
# [optional] hostname/ip and port number to listen on:
HOST=
PORT=
# [optional] extra command line options, if any:
EXTRAOPTS=
#!/bin/sh
#
# Copyright (C) 2008-2011 by JCF Ploemen <linux@jp.pp.ru>
# released under GPL, version 2 or later
################################################
# #
# TO CONFIGURE EDIT /etc/default/sabnzbdplus #
# #
################################################
### BEGIN INIT INFO
# Provides: sabnzbdplus
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Should-Start: NetworkManager
# Should-Stop: NetworkManager
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SABnzbd+ binary newsgrabber
# Description: SABnzbd+ is a web-based binary newsgrabber with nzb
# support, designed to download files from Usenet.
# This script provides that functionality as a system
# service, starting the program on boot.
### END INIT INFO
DAEMON=/usr/src/sabnzbd/SABnzbd.py
SETTINGS=/etc/default/sabnzbdplus
([ -x $DAEMON ] && [ -r $SETTINGS ]) || exit 0
DESC="SABnzbd+ binary newsgrabber"
DEFOPTS="--daemon"
PYTHONEXEC="^$(sed -n '1s/^#\!\([a-z0-9\.\/]\+\)\(.*\)/\1(\2)?/p' $DAEMON)"
PIDFILE=/var/run/sabnzbdplus.pid
SETTINGS_LOADED=FALSE
# these are only accepted from the settings file
unset USER CONFIG HOST PORT EXTRAOPTS
. /lib/lsb/init-functions
check_retval() {
if [ $? -eq 0 ]; then
log_end_msg 0
return 0
else
log_end_msg 1
exit 1
fi
}
is_running() {
# returns 0 when running, 1 otherwise
PID="$(pgrep -f -x -u ${USER%:*} "$PYTHONEXEC $DAEMON $DEFOPTS.*")"
RET=$?
[ $RET -gt 1 ] && exit 1 || return $RET
}
load_settings() {
if [ $SETTINGS_LOADED != "TRUE" ]; then
. $SETTINGS
[ -z "$USER" ] && {
log_warning_msg "$DESC: not configured, aborting. See $SETTINGS";
return 1; }
[ -z "${USER%:*}" ] && exit 1
OPTIONS="$DEFOPTS"
[ -n "$CONFIG" ] && OPTIONS="$OPTIONS --config-file $CONFIG"
[ -n "$HOST" ] && SERVER="$HOST" || SERVER=
[ -n "$PORT" ] && SERVER="$SERVER:$PORT"
[ -n "$SERVER" ] && OPTIONS="$OPTIONS --server $SERVER"
[ -n "$EXTRAOPTS" ] && OPTIONS="$OPTIONS $EXTRAOPTS"
SETTINGS_LOADED=TRUE
fi
return 0
}
start_sab() {
load_settings || exit 0
if ! is_running; then
log_daemon_msg "Starting $DESC"
start-stop-daemon --quiet --chuid $USER --start --exec $DAEMON -- $OPTIONS
check_retval
# create a pidfile; we don't use it but some monitoring app likes to have one
[ -w $(dirname $PIDFILE) ] && \
pgrep -f -x -n -u ${USER%:*} "$PYTHONEXEC $DAEMON $OPTIONS" > $PIDFILE
else
log_success_msg "$DESC: already running (pid $PID)"
fi
}
stop_sab() {
load_settings || exit 0
if is_running; then
TMPFILE="$(mktemp --tmpdir sabnzbdplus.XXXXXXXXXX)"
[ $? -eq 0 ] || exit 1
trap '[ -f "$TMPFILE" ] && rm -f "$TMPFILE"' EXIT
echo "$PID" > "$TMPFILE"
log_daemon_msg "Stopping $DESC"
start-stop-daemon --stop --user ${USER%:*} --pidfile "$TMPFILE" --retry 30
check_retval
else
log_success_msg "$DESC: not running"
fi
[ -f $PIDFILE ] && rm -f $PIDFILE
}
case "$1" in
start)
start_sab
;;
stop)
stop_sab
;;
force-reload|restart)
stop_sab
start_sab
;;
status)
load_settings || exit 4
if is_running; then
log_success_msg "$DESC: running (pid $PID)"
else
log_success_msg "$DESC: not running"
[ -f $PIDFILE ] && exit 1 || exit 3
fi
;;
*)
log_failure_msg "Usage: $0 {start|stop|restart|force-reload|status}"
exit 3
;;
esac
exit 0

Add role account

useradd --system --shell /bin/false --no-create-home --home /home/sabnzbd sabnzbd
ln --symbolic /usr/src/sabnzbd /home/sabnzbd

Download source

cd /usr/src/
git clone git://github.com/sabnzbd/sabnzbd.git
chown --recursive sabnzbd:sabnzbd sabnzbd

Install dependencies

apt-get install python python-cheetah python-configobj python-feedparser python-dbus python-openssl python-support python-yenc par2 zip

unrar (non-free version)

In order to install the non-free version of unrar, you will need to have non-free defined in /etc/apt/sources.list

/etc/apt/sources.list

deb http://http.us.debian.org/debian wheezy main contrib non-free

apt-get update

You should see the non-free version now when you search for unrar

apt-cache search unrar

unrar - Unarchiver for .rar files (non-free version)

apt-get install unrar

par2 (experimental replacement)

You can get a dramatic performance increase while repairing archives by using a multithreaded version of par2.

cd /usr/src
wget 'http://chuchusoft.com/par2_tbb/par2cmdline-0.4-tbb-20100203.tar.gz'
tar -xvzf par2cmdline-0.4-tbb-20100203.tar.gz
cd par2cmdline-0.4-tbb-20100203
sed -i '1s/^/#include <memory>\n/' {par2cmdline,commandline,par2creator,par2repairer}.cpp
ln -s /usr/bin/aclocal /usr/bin/aclocal-1.10
ln -s /usr/bin/automake /usr/bin/automake-1.10
apt-get install libtbb-dev
./configure
make
strip par2
mv /usr/bin/par2 /usr/bin/par2.bak
mv par2 /usr/bin

Install init scripts

cp sabnzbdplus.init /etc/init.d/sabnzbdplus
cp sabnzbdplus.default /etc/defaults/sabnzbdplus
chmod +x /etc/init.d/sabnzbdplus

Start

/etc/init.d/sabnzbdplus start

Configure

SABnzbd+ can be configured remotely with the help of port forwarding.

ssh -L 8080:localhost:8080 <server>

Opening a browser to http://localhost:8080 should present you with the Quick-Start Wizard

Add it to default runlevel

update-rc.d sabnzbdplus defaults

Updating

Due to the way sabnzbd development occurs, master is always a stable branch.

Updating is as simple as:

cd /usr/src/sabnzbd
sudo -u sabnzbd git pull

Then restart the sabnzbd daemon with

/etc/init.d/sabnzbdplus restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment