Working Gentoo Ebuild for sabnzbd-0.4.2

Feel free to talk about anything and everything in this board.
Post Reply
User avatar
mantis006
Release Testers
Release Testers
Posts: 17
Joined: January 28th, 2008, 5:06 am
Contact:

Working Gentoo Ebuild for sabnzbd-0.4.2

Post by mantis006 »

(EDIT: I have a working ebuild, see my post below about it.)
[updated to shutdown properly (using curl and /sabnzbd/shutdown)]

Figured this might help someone down the line:
Working with what rullerz built for .25/.27 a looonng time ago, I was able to get some simple conf.d/init.d scripts and running under another user and working almost as nicely as the .27 ebuild had things for .4beta2.

contents of /etc/init.d/sabnzbd+ (put the plus in so it doesn't break my old .27 install)

Code: Select all

#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

opts="start stop"

depend() {
    need net
}

start() {

    ebegin "Starting SABnzbd+"

    if ! check_config ; then
        eend 1
        return 1
    fi

    start-stop-daemon --quiet --start -c ${SAB_USER}:${SAB_GROUP} \
        --exec /var/lib/SABnzbd+/sabnzbd/SABnzbd.py -- -s ${SAB_HOSTNAME}:${SAB_PORT} -d &> /dev/null
    eend $?
}

stop() {
    ebegin "Stopping SABnzbd+"
    curl -s http://${SAB_HOSTNAME}:${SAB_PORT}/sabnzbd/shutdown > /dev/null
    eend $?
}

check_config() {
    if [ ! -e ${SAB_CONFIGFILE} ] ; then
        eerror "ERROR: can't find ${SAB_CONFIGFILE}."
        return 1
    else
        return 0
    fi
}
contents of /etc/conf.d/sabnzbd+

Code: Select all

# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
# /etc/conf.d/sabnzbd+
# Config file for sabnzbd+ init script

# Which user to run sabnzbd as (make sure the user exists on your system)
SAB_USER="sabnzbd"
SAB_GROUP="sabnzbd"

# What hostname and port should sabnzbd+ listen on?  (I'm assuming ${HOSTNAME} returns something useful on your network)
SAB_HOSTNAME=${HOSTNAME}
SAB_PORT="8080"

# Location of config file.
# Make sure the user specified above can read this file.
#this feature doesn't work right now, just change the symbolic link in
#	/var/lib/SABnzbd+/.sabnzbd/sabnzbd.ini -> ?
#(with this feature enabled and used, it throws weird "cannot write to log" errors)
#SAB_CONFIGFILE="/etc/SABnzbd+.conf"
* I made a user/group called sabnzbd:sabnzbd, put the user's home in /var/lib/SABnzbd+ with nologin shell. 
* Copied SABnzbd-0.4.0Beta2 to /var/lib/SABnzbd+/.SABnzbd-0.4.0Beta2. 
* symlinked /var/lib/SABnzbd+/sabnzbd -> /var/lib/SABnzbd+/.SABnzbd-0.4.0Beta2
* copied a .sabnzbd folder from my user dir (from running regularly) to /var/lib/SABnzbd+/.sabnzbd
* symlinked both {/var/lib/SABnzbd+/.sabnzbd/sabnzbd.ini, /var/lib/SABnzbd+/sabnzbd/sabnzbd.ini} -> /etc/SABnzbd+.conf (read the notes in the conf.d file as to how the -f flag didn't seem to work, one of these links are probably not needed, i'll look into it later)
* chown -R sabnzbd:sabnzbd /var/lib/SABnzbd+
* set permissions to your specifications on /etc/SABnzbd+.conf (i choose sabnzbd:sabnzbd w/ 660 mask, you may prefer 600)

From there, run

Code: Select all

/etc/init.d/sabnzbd+ start
and cross your fingers (don't forget execute permission for that file)
if you would like this to run at startup:

Code: Select all

rc-update add sabnzbd+ default
I think that since things flow as smoothly as they have been with upgrades, upgrading should be as easy as clearing the queue/history, copying the new install to /var/lib/SABnzbd+ and modifying the smylink to point to the new install.

I may be working on an ebuild down the road; but, it works for me now and i'm a little strapped on spare time with finals coming up.  Maybe I'll write one for 0.4.0 final.

Things to consider:
I just decided to throw this in /var/lib to be consistent with the other "services" on this box.  It may be more appropriate to place it in /opt as this install is done w/o the package manager and could break things down the line.  I did something very similar with azureus bittorrent client using the WebUI plugin so that's something to keep in mind if you still BTorrent. 

Enjoy!
Last edited by mantis006 on July 28th, 2008, 11:09 am, edited 1 time in total.
~Chris
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: How I daemonized sabnzbd+ on Gentoo Linux this time [still needs work though

Post by shypike »

I'm not very familiar with these concepts, but what I cannot find is how SABnzbd is actually stopped?
I hope it's not a blunt process termination.

Either stop SABnzbd through the web-api (http://localhost:port/sabnzbd/api?shutdown) or send it a Signal 3 (Control-C).
In both cases it needs time to write everything to disk. Especially if you have a large memory cache anything between
100K and 100M might need saving.
Otherwise it cannot save its state to disk, potentially giving all sorts of restart problems.
User avatar
mantis006
Release Testers
Release Testers
Posts: 17
Joined: January 28th, 2008, 5:06 am
Contact:

Re: How I daemonized sabnzbd+ on Gentoo Linux this time [still needs work though]

Post by mantis006 »

that's a good idea for using the api to shutdown rather than what i'm using. something as simple as a

Code: Select all

curl -s http://${hostname}:${port}/sabnzbd/shutdown > /dev/null
should do it (i tried the api=shutdown, didn't work; i'm going to just make variables for hostname and port probably).  I'll play around with this later and post my results.
Last edited by mantis006 on April 28th, 2008, 8:32 pm, edited 1 time in total.
~Chris
User avatar
mantis006
Release Testers
Release Testers
Posts: 17
Joined: January 28th, 2008, 5:06 am
Contact:

Re: How I daemonized sabnzbd+ on Gentoo Linux this time [still needs work though]

Post by mantis006 »

ok, i updated the init and conf scripts given in the first post to use curl to shutdown properly.
To generalize this for most users, I just made SAB_HOSTNAME=$HOSTNAME, which will most likely work; but, can be overrided easily in the conf.d script.

hope this is cleaner and more useful.
Last edited by mantis006 on April 28th, 2008, 9:09 pm, edited 1 time in total.
~Chris
Movax
Newbie
Newbie
Posts: 3
Joined: June 20th, 2008, 10:35 am

Re: How I daemonized sabnzbd+ on Gentoo Linux this time [still needs work though

Post by Movax »

How I did it:

Code: Select all

sabnzb:~# cat /etc/init.d/sabnzbd
#!/bin/sh
#
# Start/stops the SABnzbd.py daemon.
#
#

# Defaults
RUN_MODE="daemons"
SABNZBDPID=/var/run/sabnzbd.pid
#CONFIGFILE=/etc/SABnzbd/SABnzbd.conf
# clear conflicting settings from the environment
unset TMPDIRa

# See if the daemon is there
test -x /usr/bin/SABnzbd.py || exit 0

case "$1" in
        start)
                echo -n "Starting SABnzbd daemon:"

                start-stop-daemon --start --chuid sabnzbuser -b --pidfile $SABNZBDPID --make-pidfile --exec /usr/bin/SABnzbd.py -- -b 0 -f /etc/SABnzbd/SABnzbd.ini
                echo "."
                ;;
        stop)
                echo -n "Stopping SABnzbd daemon: "

                start-stop-daemon --stop --quiet --pidfile $SABNZBDPID
                # Wait a little and remove stale PID file
                sleep 1
                if [ -f $SABNZBDPID ] && ! ps h `cat $SABNZBDPID` > /dev/null
                then
                        # Stale PID file (process was succesfully stopped),
                        # remove it!
                        rm -f $SABNZBDPID
                fi
                echo "."

                ;;
        reload)
                echo -n "Reloading SABnzbd"
                start-stop-daemon --stop --signal HUP --pidfile $SABNZBDPID

                echo "."
                ;;
        restart|force-reload)
                $0 stop
                sleep 1
                $0 start
                ;;
        *)
                echo "Usage: /etc/init.d/sabnzbd {start|stop|reload|restart|force-reload}"
                exit 1
                ;;
esac

exit 0
Stole the script form some standard unix startup thing..
Not sure how nicely it stops the service, though it seems to work with no issues.
User avatar
mantis006
Release Testers
Release Testers
Posts: 17
Joined: January 28th, 2008, 5:06 am
Contact:

Re: How I daemonized sabnzbd+ on Gentoo Linux this time [still needs work though]

Post by mantis006 »

As stated before, it would probably be best to use sabnzbd's system of shutting down instead.  I think the killing off of processes with start-stop-daemon will screw with anything that's currently being processed (most likely mess up post-processing).  You also have some variables declared in your init.d script that may be more appropriately located in /etc/conf.d/; but, that really is a matter of preference and what is common for your distro.

I've been thinking of reading up on portage's slot support for packages and symlink use flags to make a system similar to downloading kernel sources works.  Basically, you would download and extract the tarball of a sabnzbd+ release to somewhere, then symlink to the "current" version you wish to use.  There wouldn't be package overlap or registering with python (like in previous ebuilds using setup.py) and config files can be symlinked to /etc/sabnzbd*.  currently i'm just extracting the zips to /var/lib/SABnzbd+/.SABnzbd-{version} and symlinking /var/lib/SABnzbd+/sabnzbd.  The sabnzbd user's home directory is set to /var/lib/SABnzbd+ so the .sabnzbd config directory should be shared between versions.

I will probably have something more with the next major release, I don't really feel like working on an ebuild for RC's.

EDIT: I suck and haven't worked on anything yet  :-[ maybe I'll work on it now?
Last edited by mantis006 on July 28th, 2008, 1:33 am, edited 1 time in total.
~Chris
User avatar
mantis006
Release Testers
Release Testers
Posts: 17
Joined: January 28th, 2008, 5:06 am
Contact:

SUCCESS!

Post by mantis006 »

Hey guys,

I just finished an ebuild for Gentoo's portage system with a modification of a super old setup.py script (0.2.7 i think).  It accomplishes much of what you guys are looking for as far as installation that is consistent with how other packages install.

sabnzbd-0.4.2.ebuild (I follow rullerz's idea of net-nntp/sabnzbd as the atom name, this is an ebuild file -just a glorified bash script)

Code: Select all

# Copyright 1999-2007 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: $



inherit distutils



DESCRIPTION="Binary Newsgrabber written in Python, server-oriented using a web-interface.The active successor of the abandoned SABnzbd project."

HOMEPAGE="http://sourceforge.net/projects/sabnzbd/"

SRC_URI="mirror://sourceforge/sabnzbdplus/sabnzbd-${PV}-src.tar.gz"

HOMEDIR="${ROOT}var/lib/${PN}"

DHOMEDIR="var/lib/${PN}"



LICENSE="GPL-2"

SLOT="0"

KEYWORDS="~amd64"

IUSE="symlink unrar unzip feedparser par yenc"



RDEPEND=">=dev-lang/python-2.4.4

		~dev-python/cherrypy-2.2.1

		>=dev-python/cheetah-2.0.1

		>=dev-python/elementtree-1.2.6

		app-text/dos2unix

		unrar? ( >=app-arch/unrar-3.6.6 )

		unzip? ( >=app-arch/unzip-5.5.2 )

		feedparser? ( >=dev-python/feedparser-4.1 )

		par? ( >=app-arch/par2cmdline-0.4 )

		yenc? ( >=dev-python/yenc-0.3 )"



DEPEND=""





src_unpack() {

	unpack "${A}" || die

	mv ${WORKDIR}/SABnzbd-${PV}/* "${WORKDIR}/"

	einfo "copy setup.py to ${WORKDIR}/setup.py"

	cp "${FILESDIR}/${PN}-${PV}-gentoo-setup.py" "${WORKDIR}/setup.py"

}



src_compile() {

	distutils_src_compile

}



pkg_preinst() {

	#Create group and user

	enewgroup "${PN}"

	enewuser "${PN}" -1 /bin/false "${HOMEDIR}" "${PN}"

}



src_install() {

	distutils_src_install



	#Init scripts

	newinitd "${FILESDIR}"/"${PN}".init "${PN}"

	newconfd "${FILESDIR}"/"${PN}".conf "${PN}"



	cd "${D}"



	#Config file (permissions for this are really up in the air, should this be sabnzbd owned with mask=600?)

	insinto /etc

	newins "${FILESDIR}/${PN}-${PV}".ini "${PN}".conf

	fowners root:"${PN}" etc/"${PN}".conf

	fperms 660 etc/"${PN}".conf



	#Create all default dirs

	keepdir "${DHOMEDIR}"

	fowners "${PN}":"${PN}" "${DHOMEDIR}"



	keepdir "${DHOMEDIR}"/download

	fowners "${PN}":"${PN}" "${DHOMEDIR}"/download

	fperms 775 "${DHOMEDIR}"/download



	keepdir "${DHOMEDIR}"/complete

	fowners "${PN}":"${PN}" "${DHOMEDIR}"/complete

	fperms 775 "${DHOMEDIR}"/complete



	keepdir "${DHOMEDIR}"/nzb_backup

	fowners "${PN}":"${PN}" "${DHOMEDIR}"/nzb_backup

	fperms 775 "${DHOMEDIR}"/nzb_backup



	keepdir "${DHOMEDIR}"/cache

	fowners "${PN}":"${PN}" "${DHOMEDIR}"/cache



	keepdir /var/log/sabnzbd

	fowners "${PN}":"${PN}" "${ROOT}"var/log/"${PN}"



	keepdir "${DHOMEDIR}"/dirscan

	fowners "${PN}":"${PN}" "${DHOMEDIR}"/dirscan

	fperms 775 "${DHOMEDIR}"/dirscan



	#Add themes

	cd "${D}"

	mv usr/interfaces usr/share/"${PN}"-"${PV}"/

	#cp -R "${WORKDIR}"/interfaces/Plush usr/share/"${PN}"-"${PV}"/Plush

	#cp -R "${WORKDIR}"/interfaces/smpl usr/share/"${PN}"-"${PV}"/smpl

	#cp -R "${WORKDIR}"/interfaces/iphone usr/share/"${PN}"-"${PV}"/iphone



	#Symlink /usr/share/SABnzbd to this version

	if use symlink; then

		cd "${D}"usr/share/

		dosym "${PN}-${PV}" "${PN}"

	fi



	#fix permission on themes

	fowners root:sabnzbd -R usr/share/${PN}-${PV}

}



pkg_postinst() {

	einfo "Default directory: ${HOMEDIR}"

	einfo "Templates can be found in: ${ROOT}usr/share/${PN}-${PV}"

	einfo ""

	einfo "Run: gpasswd -a <user> sabnzbd"

	einfo "to add an user to the sabnzbd group so it can edit sabnzbd files"

	einfo ""

	ewarn "Please configure ${ROOT}etc/conf.d/${PN} before starting!"

	einfo ""

	einfo "Start with ${ROOT}etc/init.d/${PN} start"

}
files/sabnzbd-0.4.2-gentoo-setup.py (used by distutils to install sabnzbd in python)

Code: Select all

#!/usr/bin/env python



Win32ConsoleName = 'SABnzbd-console.exe'

Win32WindowName  = 'SABnzbd.exe'



import sabnzbd

from distutils.core import setup



# py2exe usage: python setup.py py2exe



try:

    import glob

    import sys

    import os

    import py2exe

except ImportError:

    py2exe = None



print sys.argv[0]



if (len(sys.argv) < 2) or sys.argv[1] != 'py2exe':

    py2exe = None



options = dict(

      name = 'SABnzbd',

      version = sabnzbd.__version__,

      url = 'http://sourceforge.net/projects/sabnzbdplus',

      author = 'The ShyPike & Gregor Kaufmann',

      author_email = '[email protected]',

      description = 'SABnzbd ' + str(sabnzbd.__version__),

      scripts = ['SABnzbd.py'],

      packages = ['sabnzbd', 'sabnzbd.utils', 'sabnzbd.utils.multiauth'],

      platforms = ['posix'],

      license = 'GNU General Public License 2 (GPL2)',

      data_files = [

          ('interfaces/Default/templates', glob.glob("interfaces/Default/templates/*.tmpl")),

          ('interfaces/Default/templates/static/stylesheets', glob.glob('interfaces/Default/templates/static/stylesheets/*.*')),

	  ('interfaces/Default/templates/static/stylesheets/colorschemes', glob.glob('interfaces/Default/templates/static/stylesheets/colorschemes/*.*')),

          ('interfaces/Default/templates/static/images', glob.glob('interfaces/Default/templates/static/images/*.ico')),

	  ('interfaces/Default/templates/static/javascript', glob.glob('interfaces/Default/templates/static/javascript/*.js')),



          ('interfaces/smpl/templates', glob.glob("interfaces/smpl/templates/*.*")),

          ('interfaces/smpl/templates/static', glob.glob("interfaces/smpl/templates/static/*.*")),

          ('interfaces/smpl/templates/static/images', glob.glob("interfaces/smpl/templates/static/images/*.*")),

	  ('interfaces/smpl/templates/static/images/nuvola', glob.glob("interfaces/smpl/templates/static/images/nuvola/*.*")),

          ('interfaces/smpl/templates/static/MochiKit', glob.glob("interfaces/smpl/templates/static/MochiKit/*.*")),

          ('interfaces/smpl/templates/static/PlotKit', glob.glob("interfaces/smpl/templates/static/PlotKit/*.*")),

          ('interfaces/smpl/templates/static/excanvas', glob.glob("interfaces/smpl/templates/static/excanvas/*.*")),

          ('interfaces/smpl/templates/static/stylesheets', glob.glob("interfaces/smpl/templates/static/stylesheets/*.*")),

	  ('interfaces/smpl/templates/static/stylesheets/colorschemes', glob.glob("interfaces/smpl/templates/static/stylesheets/colorschemes*.*")),



          ('interfaces/Plush/templates', glob.glob("interfaces/Plush/templates/*.*")),

          ('interfaces/Plush/templates/static', glob.glob("interfaces/Plush/templates/static/*.*")),

          ('interfaces/Plush/templates/static/images', glob.glob("interfaces/Plush/templates/static/images/*.*")),

          ('interfaces/Plush/templates/static/images/plush-default', glob.glob("interfaces/Plush/templates/static/images/plush-default/*.*")),

          ('interfaces/Plush/templates/static/images/plush-default/config', glob.glob("interfaces/Plush/templates/static/images/plush-default/config/*.*")),

          ('interfaces/Plush/templates/static/images/plush-default/nzo', glob.glob("interfaces/Plush/templates/static/images/plush-default/nzo/*.*")),

          ('interfaces/Plush/templates/static/javascripts', glob.glob("interfaces/Plush/templates/static/javascripts/*.*")),

          ('interfaces/Plush/templates/static/stylesheets', glob.glob("interfaces/Plush/templates/static/stylesheets/*.*")),



	  ('interfaces/iphone/templates', glob.glob("interfaces/iphone/templates/*.*")),

	  ('interfaces/iphone/templates/static', glob.glob("interfaces/iphone/templates/static/*.*")),

	  ('interfaces/iphone/templates/static/iui', glob.glob("interfaces/iphone/templates/static/iui/*.*")),

	  ('interfaces/iphone/templates/MochiKit', glob.glob("interfaces/iphone/templates/static/MochiKit/*.*")),

      ]

)



if py2exe:

    program = [ {'script' : 'SABnzbd.py', 'icon_resources' : [(0, "interfaces/Default/templates/static/images/favicon.ico")] } ]

    options['options'] = {"py2exe": {"bundle_files": 1, "packages": "xml,cherrypy.filters,Cheetah", "optimize": 2, "compressed": 0}}



    # Generate the console-app

    options['console'] = program

    setup(**options)

    try:

        if os.path.exists("dist/%s" % Win32ConsoleName):

            os.remove("dist/%s" % Win32ConsoleName)

        os.rename("dist/%s" % Win32WindowName, "dist/%s" % Win32ConsoleName)

    except:

        print "Cannot create dist/%s" % Win32ConsoleName

        exit(1)

    

    # Make sure that the root files are DOS format

    for file in options['data_files'][0][1]:

        os.system("unix2dos --safe dist/%s" % file)

    os.remove('dist/Sample-PostProc.sh')



    # Generate the windowed-app (skip datafiles now)

    del options['console']

    del options['data_files']

    options['windows'] = program

    setup(**options)



else:

    # Prepare Source distribution package.

    # Make sure all source files are Unix format

    import shutil



    root = 'srcdist'

    root = os.path.normpath(os.path.abspath(root))

    if not os.path.exists(root):

        os.mkdir(root)



    # Copy the data files

    for set in options['data_files']:

        dest, src = set

        ndir = root + '/' + dest

        ndir = os.path.normpath(os.path.abspath(ndir))

        if not os.path.exists(ndir):

            os.makedirs(ndir)

        for file in src:

            shutil.copy2(file, ndir)

            front, ext = os.path.splitext(file)

            base = os.path.basename(file)

            if ext.lower() in ('.py', '.pl', '.txt', '.html', '.css', '.tmpl', ''):

                os.system("dos2unix --quiet --safe %s" % ndir + '/' + base)



    # Copy the script files

    for name in options['scripts']:

        file = os.path.normpath(os.path.abspath(name))

        shutil.copy2(file, root)

        base = os.path.basename(file)

        fullname = os.path.normpath(os.path.abspath(root + '/' + base))

        os.system("dos2unix --quiet --safe %s" % fullname)



    # Copy all content of the packages (but skip backups and pre-compiled stuff)

    for unit in options['packages']:

        unitpath = unit.replace('.','/')

        dest = os.path.normpath(os.path.abspath(root + '/' + unitpath))

        if not os.path.exists(dest):

            os.makedirs(dest)

        for name in glob.glob("%s/*.*" % unitpath):

            file = os.path.normpath(os.path.abspath(name))

            front, ext = os.path.splitext(file)

            base = os.path.basename(file)

            fullname = os.path.normpath(os.path.abspath(dest + '/' + base))

            if ext.lower() not in ('.pyc', '.pyo', '.bak'):

                shutil.copy2(file, dest)

                os.system("dos2unix --quiet --safe %s" % fullname)





setup(**options)
/files/sabnzbd-0.4.2-ini (/etc/sabnzbd.conf - this is the default config generated by sabnzbd-0.4.2 with some default directorties set)

Code: Select all

__version__ = 18

[misc]

log_dir = /var/log/sabnzbd

auto_browser = 0

permissions = 0775

check_new_rel = 1

replace_spaces = 0

fail_on_crc = 0

enable_filejoin = 0

enable_unzip = 1

enable_unrar = 1

enable_par_cleanup = 1

par_option = ""

config_lock = 0

safe_postproc = 0

pause_on_post_processing = 0

cleanup_list = ""

ignore_samples = 0

send_group = 0

download_dir = /var/lib/sabnzbd/download

download_free = 0

complete_dir = /var/lib/sabnzbd/complete

script_dir = "/var/lib/sabnzbd/scripts"

nzb_backup_dir = /var/lib/sabnzbd/nzb_backup

cache_dir = /var/lib/sabnzbd/cache

dirscan_dir = /var/lib/sabnzbd/dirscan

dirscan_speed = 5

refresh_rate = 0

rss_rate = 60

bandwith_limit = 0

cache_limit = 0

email_server = ""

email_to = ""

email_from = ""

email_account = ""

email_pwd = ""

email_endjob = 0

email_full = 0

schedlines = ,

dirscan_opts = 3

dirscan_script = ""

top_only = 1

auto_sort = 0

enable_tv_sorting = 0

tv_sort_string = ""

web_color = ""

web_color2 = ""

host = 192.168.200.22

port = 8080

web_dir = /usr/share/sabnzbd-0.4.2/Default

web_dir2 = ""

username = ""

password = ""

[logging]

enable_cherrypy_logging = 1

log_level = 1

max_log_size = 5M

log_backups = 5

[newzbin]

username = ""

password = ""

bookmarks = 0

unbookmark = 0

bookmark_rate = 60

[servers]

[rss]

[categories]

[[unknown]]

newzbin = Unknown

dir = Unknown

[[anime]]

newzbin = Anime

dir = Anime

[[apps]]

newzbin = Apps

dir = Apps

[[books]]

newzbin = Books

dir = Books

[[consoles]]

newzbin = Consoles

dir = Consoles

[[emulation]]

newzbin = Emulation

dir = Emulation

[[games]]

newzbin = Games

dir = Games

[[misc]]

newzbin = Misc

dir = Misc

[[movies]]

newzbin = Movies

dir = Movies

[[music]]

newzbin = Music

dir = Music

[[pda]]

newzbin = PDA

dir = PDA

[[resources]]

newzbin = Resources

dir = Resources

[[tv]]

newzbin = TV

dir = TV
/files/sabnzbd.conf (this goes in /etc/conf.d/sabnzbd)

Code: Select all

# Copyright 1999-2007 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: $



# /etc/conf.d/sabnzbd

# Config file for sabnzbd init script



# Which user to run sabnzbd as, you should change this.

SAB_USER="sabnzbd"

SAB_GROUP="sabnzbd"



# This overrides the contents of /etc/sabnzbd.conf, needed for wget shutdown to work in init (short of writing some crazy regex for the config)

SAB_HOSTNAME="127.0.0.1"

SAB_PORT="8080"



# Location of config file.

# Make sure the user specified above can read this file. (if you want to change options from the webUI, give it write)

SAB_CONFIGFILE="/etc/sabnzbd.conf"
/files/sabnzbd.init (/etc/init.d/sabnzbd):

Code: Select all

#!/sbin/runscript

# Copyright 1999-2007 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: $





opts="start stop"



depend() {

    need net

}



start() {

    ebegin "Starting SABnzbd"

    if ! check_config ; then

        eend 1

        return 1

    fi



    start-stop-daemon --quiet --start -c ${SAB_USER}:${SAB_GROUP} \

        --exec /usr/bin/SABnzbd.py -- \

        -s ${SAB_HOSTNAME}:${SAB_PORT} -f ${SAB_CONFIGFILE} -d &> /dev/null

    eend $?

}



stop() {

    ebegin "Stopping SABnzbd"

    URL="http://${SAB_HOSTNAME}:${SAB_PORT}/sabnzbd/shutdown"

    if [ -x /usr/bin/wget ] ; then

	/usr/bin/wget -q --delete-after "${URL}"

    elif [ -x /usr/bin/curl ] ; then

	/usr/bin/curl --silent "${URL}" > /dev/null 2> /dev/null

    else

	ewarn "missing wget and curl, ending all processes named SABnzbd.py"

	start-stop-daemon --quiet --stop --name SABnzbd.py

    fi

    eend $?

}



check_config() {

    if [ ! -e ${SAB_CONFIGFILE} ] ; then

        eerror "ERROR: can't find ${SAB_CONFIGFILE}."

        return 1

    else

        return 0

    fi

}
I might take the symlink useflag part out in the future and just make the installer select the most recently installed version by default.  SABnzbd isn't gcc or python so it's not as important to have multiple versions at your fingertips...

as always, corretions/suggestions are welcome.

EDIT:  bug for sabnzbd ebuilds has these files uploaded there: http://bugs.gentoo.org/show_bug.cgi?id=132590
Last edited by mantis006 on July 28th, 2008, 11:54 am, edited 1 time in total.
~Chris
Post Reply