Publish SABnzbd via Bonjour

If you have AVAHI installed on your FreeBSD box, then create a file called sabnzbd.service in the /usr/local/etc/avahi/services directory. This will publish the server via Bonjour, so you can access it easily using a Bonjour enabled browser, such as Safari.

The sabnzbd.service file should have the following content:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">

<!-- See avahi.service(5) for more information about this configuration file -->

<service-group>

  <name replace-wildcards="yes">SABnzbd [%h]</name>

  <service>
    <type>_http._tcp</type>
    <port>8080</port>
    <txt-record>path=/queue</txt-record>
  </service>

</service-group>

Make sure you change the port number if you don’t use the standard SABnzbd port.

Install SABnzbd on FreeBSD

FreeBSD comes with an extensive ports collection that contains SABnzbd. Unfortunately, even in the latest FreeBSD 8.1 release, it contains SABnzbd v0.4.12 which is old and lacks a lot of cool features. There wasn’t a clear guide on how to upgrade SABnzbd to the latest version, so I decided to find out how it can be done.

What has changed?
I started out with the v0.4.12 port, but I have updated the Makefile, distinfo, so it will download the latest version of SABnzbd (currently v0.5.3). Because the new version uses a different set of files, the pkg-plist file has been updated to match the files in v0.5.3.

The v0.4.12 distribution installed some files in the Python directory, which I don’t like. It’s not a part of Python, so it shouldn’t install files in the Python directories. All SABnzbd related files are now stored in its own directory. On most installations this will be /usr/local/shared/sabnzbdplus. Even the SABnzbd.py file that is used to run the application is now stored inside this directory. A symbolic link will be created during installation from /usr/local/bin to make sure the program can be found.

Two patches are necessary to the SABnzbd.py file. First Python must be told to first look for packages in the SABnzbd directories, because SABnzbd comes with its own version of CherryPy. Another change is that the SABnzbd directory will be hardcoded to the correct path. The original version tries to detect the path automatically, but this fails when you start it from /usr/local/bin.

The last addition that I made was to include an RC-script that allows that SABnzbd can be started as a daemon during system startup.

How to install SABnzbd
The following steps should be performed to download and install SABnzbd on your FreeBSD installation:

  1. Log on with root privileges on your FreeBSD server.
  2. Go to the ports directory.
  3. Fetch the latest version of my distribution.
  4. Unpack the archive and remove the archive itself.
  5. Change to the new SABnzbd directory.
  6. Install the new version and clean up.

In code this looks like:

[root@freebsd /]# cd /usr/ports/news
[root@freebsd /usr/ports/news]# wget http://blog.ramondeklein.nl/wp-content/uploads/2010/07/sabnzbdplus-0.5.3.tar.gz
[root@freebsd /usr/ports/news]# tar -xvzf sabnzbdplus-0.5.3.tar.gz
[root@freebsd /usr/ports/news]# rm sabnzbdplus-0.5.3.tar.gz
[root@freebsd /usr/ports/news]# cd sabnzbdplus-0.5.3
[root@freebsd /usr/ports/news/sabnzbdplus-0.5.3]# make install && make clean

Now you can start SABnzbd by typing SABnzbd.py. Go to http://your-freebsd-server:8080 to check if the server is running correctly. Refer to the SABnzbd manuals for more information about configuring SABnzbd itself.

Read the next paragraphs if you want to run SABnzbd as a daemon with more restrictive privileges.

How to run SABnzbd as a daemon
Add the following lines to your /etc/rc.conf file to make sure it starts during system startup:

# SABnzbd settings
sabnzbd_enable="YES"

The default daemon runs as root, but it is better to run SABnzbd under a less-privileged account. Add the following lines to your /etc/rc.conf file to make sure the daemon runs under the ‘ramon’ account:

# SABnzbd settings
sabnzbd_enable="YES"
sabnzbd_user="ramon"

You don’t need to restart the system to test if the daemon can be started. Type the following command to start the SABnzbd daemon:

/usr/local/etc/rc.d/sabnzbd start

Stopping the daemon can be done using the following command:

/usr/local/etc/rc.d/sabnzbd stop

Always make sure you stop the daemon before you make any changes to the configuration files by hand.

Known issues

  • Make sure you run SABnzbd.py with root privileges at least once. This enables that the compiled versions can be stored. Other users probably don’t have the required privileges to store these files.
  • During deinstallation the compiled Python files are not removed. This result in some error messages. You can delete these files yourself when you deinstall the distribution.

SABnzbd distributions
The following list contains the SABnzbd distributions that I have created: