Tuesday 14 September 2010

HOWTO install SABnzbd on FreeNAS 0.7.2


Requirements -

Freenas - 0.7.2 Sabanda (revision 5266) embedded running from CF card
Platform - amd64-embedded on AMD Phenom(tm) II X2 555 Processor
4 Drives Raid 5 Array.


THIS IS ONLY FOR FREENAS VERSION 0.7.2!!!!!
There are other post that detail the older versions of freenas.


So I have been doing alot of research trying to install SABnzbd on the lastest version of Freenas which is built on FreeBSD 7.3. This will be a 2 post HOWTO, Post 1 I will show you how to install SABnzbd that is ported to FreeBSD 7.3 (SAB Ver 0.4.12). The issue with this, is that starting from FreeBSD version 7.3, the default python install is 2.6 and SAB 0.4.XXX version doesnt really like that version of python so it runs up the CPU. CPU was running above 50%. SAB recommends ver 0.5 or above for python 2.6. So Post 2 I will show you how i upgraded my version.

NOTE: I am not a developer, well not a unix dev, i do alot of web dev but never OS. I used google to help me though most of this. And this fourm, so you will find that my script is like others listed here.

OK on to it...

***** Pre Prereq *****
Turn on SSH and log on as root.

****** Prereq *****
1. I have the AMD64 version of Freenas (multi core processor), so i am downloading packages for my version, you would have to make the changes to the script. Simple Copy/Paste, replace AMD64 with i386. 
2. Since this is the embedded version, I have freenas running from a CF card (CF to IDE), we would need to install the packages to whatever HDD we mounted. In my case i have a Raid5 Mount. I named my mount "Raid5A1" - Stands for Raid 5 Array 1. Below is the folder structure.
/mnt
Raid5A1/
local/ <--- This is where i have all the packages, only accessable via SSH or SFTP
Media/ <-- This is my SMB share where all my files are.


In the script we need to define 3 different things.
hostname="freenas" <-- Server Name
dest="/mnt/Raid5A1/local" <-- Where the packages live
configuration="/mnt/Raid5A1/Media/sabnzbd" <--- Where SAB Config and downloads live.


Once you have that, you can edit the script, Save as installsab.sh and upload to /mnt/Raid5A1/
Dont worry about creating the Directory as it creates it for you.


CODE: 
#!/bin/sh
# author: Ray Matos
#date: Sept 2th 2010

python_version="2.6"

hostname="freenas"
dest="/mnt/Raid5A1/local"
configuration="/mnt/Raid5A1/Media/sabnzbd"

echo "host: $hostname"
echo "destination path: $dest"
echo "configuration path: $configuration"

mkdir ${dest}
cd ${dest}

#create temporary dummy variables and links that will disappear at either the end of the script or at reboot.
#these environment variables and symbolic links faciliate clean install on alternate directory
#this has to do with the fact that both sabnzbd and cheetah have hardcoded paths (non configurable) in either their installation or executable software
#so these will also be included in init script

echo "@@ creating symlinks and environment variables"
PKG_TMPDIR=$dest; export PKG_TMPDIR
PYTHONPATH=${dest}/lib/python${python_version}/site-packages; export PYTHONPATH
ln -s ${dest}/bin/python /usr/local/bin/python
ln -s ${dest}/bin/python${python_version} /usr/local/bin/python${python_version}
ln -s ${dest}/bin/easy_install /usr/local/bin/easy_install
ln -s ${dest}/bin/easy_install-${python_version} /usr/local/bin/easy_install-${python_version}
ln -s ${dest}/lib/python${python_version}  /usr/local/lib/python${python_version}
ln -s ${dest}/share/sabnzbdplus /usr/local/share/sabnzbdplus 

echo "@@ install sabnzbplus, unrar, unzip, yenc and par2 packages"
pkg_add -r unrar unzip par2cmdline sabnzbdplus ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-7.3-release/Latest/py26-yenc.tbz ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-7.3-release/Latest/py26-pysqlite.tbz -P $dest

echo "--Starting SABnzbd (to generate config file)--"
${dest}/bin/SABnzbd.py -f ${configuration}/sabnzbd.ini
echo "--Shutting down SABnzb--"
/usr/bin/fetch "http://$hostname:8080/sabnzbd/api?mode=shutdown"



echo "*******Done - SABnzbd should be installed*******"

rcscript=${dest}/etc/rc.d/sabnzbplus
echo "@@ creating init script: $rcscript"

echo "#! /bin/sh" > $rcscript
echo "case "\$1" in"  >> $rcscript
echo "start)" >> $rcscript
echo "echo \"Starting SABnzbd."\" >> $rcscript
echo "dest=$dest" >> $rcscript
echo "python_version=$python_version" >> $rcscript
echo "# re-create symlinks as they are placed on ramdisk and get lost on shutdown" >> $rcscript
echo "ln -s \${dest}/bin/python /usr/local/bin/python" >> $rcscript
echo "ln -s \${dest}/bin/python\${python_version} /usr/local/bin/python\${python_version}" >> $rcscript
echo "ln -s \${dest}/lib/python\${python_version}  /usr/local/lib/python\${python_version}" >> $rcscript
echo "ln -s \${dest}/share/sabnzbdplus /usr/local/share/sabnzbdplus" >> $rcscript
echo "ln -s \${dest}/share/sabnzbdplus/interfaces /usr/local/bin/interfaces" >> $rcscript
echo "ln -s \${dest}/share/sabnzbdplus/language /usr/local/bin/language" >> $rcscript
echo "PATH=\$PATH:\${dest}/bin; export PATH" >> $rcscript
echo "\${dest}/bin/SABnzbd.py -d -f ${configuration}/sabnzbd.ini" >> $rcscript
echo ";;"  >> $rcscript
echo "stop)" >> $rcscript
echo "echo \"Shutting down SABnzbd.\"" >> $rcscript
echo "/usr/bin/fetch \"http://$hostname:8080/sabnzbd/api?mode=shutdown\" > /dev/null" >> $rcscript
echo ";;"  >> $rcscript
echo "*)" >> $rcscript
echo "echo \"Usage: \$0 {start|stop}\" "  >> $rcscript
echo "exit 1"  >> $rcscript
echo ";;"  >> $rcscript
echo "esac" >> $rcscript

chmod a+x $rcscript


**** Run the Script *****


CODE: 
cd /mnt/Raid5A1/
./installsab.sh


There will be a point where you see SAB start, you might need to hit CTRL-C for it to proceed to the next steps.

***** After you run the script *****
Go find your sabnzbd.ini file, it should be located where the config location you set earlier.
Find the line that says HOST: localhost, replace localhost with your IP, in my case 192.168.50.40


Once you do that Run the following


CODE: 
/mnt/Raid5A1/local/etc/rc.d/sabnzbplus start 


Now go to http://192.168.50.40:8080/sabnzbd

It should now be installed.

***** Start and Stop on Freenas web UI *****
Go to System -> Advanced -> Command Scripts 

Add


CODE: 
/mnt/Raid5A1/local/etc/rc.d/sabnzbplus start


Type: PostInit


Add


CODE: 
/mnt/Raid5A1/local/etc/rc.d/sabnzbplus stop


Type:Shutdown


Thats it, now go and try it :))

2 comments:

  1. I'm also running FreeNAS embedded but the script didn't work for me, even after editing it for my architecture and file locations.

    It couldn't find the packages nor run the sabnzbd python server, or even create the INI file.

    Not sure whats going on here. Debating on just doing a 'full' install of freenas for this.

    ReplyDelete
  2. Same. This script doesn't work. It fails when it starts SAB to create an ini, says cheetah isn't there.

    ReplyDelete