installing subsonic on freenas (and bonus upgrade instructions)

February 2nd, 2011 by nebhead

I can’t recall if I’ve talked about FreeNAS before on this blog, but if I haven’t that may be a topic for another time.  Besides, lots of other folks have written about it in the past.  It’s great network storage for backing up all of our documents, photos, videos and music in one place with built in RAID backup.  It’s amazing.  And now with Subsonic, we have the option of installing software that can stream music (and now video) to any web browser or even smart phone on the internet.  Very cool.

Once again, I’m writing a really, really nerdy post as a public service to those out there who want to do the same and haven’t gotten enough guidance elsewhere on the internet.  Also this will serve as a persistent memory for my inevitable re-install later.  I’m sure most of my regular readers will want to stop reading at this point.

Before starting, it’s really important that you have enough space on your FreeNAS OS partition to hold Subsonic.  In the Subsonic forum it’s suggested that you carve out at least 150MB for all of the files.  I’d suggest allocating at least twice that if possible.  I’ve found that after a fair amount of use, the log file will start to grow pretty large, you may want to add codecs for transcoding, etc.  Personally this was the most painful part of the process since I had an “embedded” installation of FreeNAS on a USB flash drive which was fairly small.  During this process I used the capability within FreeNAS to backup the configuration before I re-installed.  Make sure when you re-install (if you need to) that do not choose the “embedded” option.  I installed from the CD-ROM image and chose the “full” install option onto a Hard Drive w/Data Partition (even though I will not actually use a hard drive or data partition).

The information and steps below are lovingly borrowed from the following two links, however I have mashed them up together, and added steps/made some changes that I found helpful during my experience installing the software.

  • Subsonic Forum: Sindre provided some helpful instructions to get your started on the install with FreeNAS.
  • Ozziks Blog: Huge thanks to this blog for helping with the finer points of the installation process.

Step 1: Prepare your server for the installation.

Before getting started, enable SSH access to your FreeNAS server.  You’ll find this under the web UI:  “Services >SSH”.  Set this to enable, and allow root.  You can log into your FreeNAS server by using any SSH terminal client.  Under Ubuntu (with SSH client installed) type “ssh x.x.x.x@root” (where the x.x.x.x is the IP address of your FreeNAS server).   If you have Windows use Putty.  Just remember that you must login as “root”, and not “admin”.

Setup FreeNAS’s Gateway IP.  This was something that I got hung up on for hours while trying to run the pkg_add command later in the process.  Well, maybe not hours, but it was an ah-ha moment when I finally stumbled upon the answer.  Under the FreeNAS web interface go to Network > LAN Management > Gateway = 192.168.1.1 (set this to your router’s IP address, mine happens to be 192.168.1.1).

Step 2: Download Java JRE (or JDK) package from:

http://www.freebsdfoundation.org/downloads/java.shtml

You should choose the JRE package according to your CPU architecture and FreeBSD version (if you have FreeNAS 0.7.x then you will want to download the FreeBSD 7 package, and of course based on your release, either AMD(64-bit) and i386(32-bit)).  I chose diablo-jre-freebsd7.i386.1.6.0.07.02.tbz, having FreeNas 0.7.2 and i386.  I then put this file onto my FreeNAS share drive so that you can access it directly from the shell (i.e. /mnt/share-name/path-to/file-name) later when you want to add the package.

Step 3: Install dependent packages (included the transcoders here as well, but may not be desired in your config):

$ pkg_add -v -r xtrans
$ pkg_add -v -r xproto
$ pkg_add -v -r xextproto
$ pkg_add -v -r javavmwrapper
$ pkg_add -v -r lame
$ pkg_add -v -r flac
$ pkg_add -v -r ffmpeg

UPDATE 1/10/2012:  If you run into issues with the latest versions of FreeNAS failing the pkg_add command like I did recently, the follow these instructions prior to the pkg_add commands.

Before installing the packages, if you are using FreeNAS 7.2 (based on FreeBSD 7.3), you’ll need to enter the following command:

setenv PACKAGESITE ftp://ftp-archive.freebsd.org/pub/FreeBSD-Archive/ports/i386/packages-7.3-release/Latest/

(substitute amd64 for i386 if 64-bit).

(May also work for other versions – if the version of FreeBSD is no longer considered the current release, the main mirror will no longer contain the package files, therefore the above is necessary to tell pkg_add where to find the .tbz files. You may set it permanently in ~/.cshrc if you wish it to remain sticky.)

If you have issues installing the lame codec you may also try the following.  I can’t recall if I ran into this issue or not.

$ pkg_add -r -v http://ftp.urc.ac.ru/pub/OS/FreeBSD/packages-7/Latest/lame.tbz

Step 4: Install the JRE (the .tbz file is the one you downloaded in step 2)

$ pkg_add -v /mnt/share-drive/diablo-jre-freebsd7.i386.1.6.0.07.02.tbz

Of course your version of the file and location may be different, so don’t copy/paste this portion.

Step 5: Download Subsonic standalone version and install it in /var/subsonic/standalone on your FreeNAS, as described here.  Just like with the Java package, I put the Subsonic Tarball on the share drive somewhere (i.e. In SSH:

$ mkdir /var/subsonic
$ mkdir /var/subsonic/standalone
$ cd /var/subsonic/standalone
$ tar xvzf /mnt/share-name/path-to/subsonic-x.x-standalone.tar.gz

Some folks suggest changing the permissions of all of the files at this point.  Technically it will probably work just fine untouched.  But if you want:

$ chmod 777 *.*

Step 6: Modify the subsonic.sh file.

/var/subsonic/standalone/subsonic.sh

If you are editing under Windows, do yourself a favor and save the file in ASCII format so as not to cause issues.  The fist time around I made changes in my Windows text editor and it introduced all kinds of invisible line breaks and null characters which caused the script to fail under BSD.   Just… don’t.

I also found an issue with the subsonic.h file, as shipped, under my FreeNAS implementation and am not quite sure why it doesn’t work.  It may work out of the box for you, but for some reason it was broken for me.  If you run into the same issue, you can make the following changes.

From:

cd $(dirname $0)
if [ -L $0 ] && ([ -e /bin/readlink ] || [ -e /usr/bin/readlink ]); then
cd $(dirname $(readlink $0))
fi

To:

cd /var/subsonic/standalone
#if [ -L $0 ] && ([ -e /bin/readlink ] || [ -e /usr/bin/readlink ]); then
#cd $(dirname $(readlink $0))
#fi

Step 7: Copy codecs into the Subsonic transcode directory:

mkdir /var/subsonic/transcode
cp /usr/local/bin/lame /var/subsonic/transcode/
cp /usr/local/bin/flac /var/subsonic/transcode/
cp /usr/local/bin/ffmpeg /var/subsonic/transcode/

There is one more step to get codecs to function properly that we’ll cover later.  If you installed some other codecs in step 3, then you’ll want to copy those to the transcode directory as well.

Step 7: In the FreeNAS web interface, go to System > Advanced > Command script and add the following “PostInit” script:

/var/subsonic/standalone/subsonic.sh

Step 8: Reboot FreeNAS, and go to http://<your-freenas-server>:4040 to start using Subsonic.

Step 9: Configure your transcoder settings.  In the Subsonic web interface go to “Settings > Transcoding”.

In this example, I’ve set up FLAC to transcode to WAV, then to MP3.   On the line reads “flac > mp3″ modify the following:

Step 1 = flac -c -s -d %s
Step 2 = lame -b 320 – -

NOTE: This hard-codes the bitrate to 320kbps, which is presumptuous.  But hey, that’s what FLAC is all about right?  High quality.

My FreeNAS server is an under-powered system (mostly because it never needed to be powerful), so transcoding FLAC to MP3 basically consumes 100% of the processor bandwidth.  Listening to FLAC’s is something I will probably do sparingly.  Your mileage may vary.

Summary: It looks hard, but I’ve made all the mistakes for you, so this guide should save you some serious time.  If you run into any issues, Google is always your friend.

And in closing, if you haven’t yet donated to the project, I urge you to do so.  Sindre (the developer of Subsonic) obviously put a lot of hard work into this and it is just flat-out great software.  He deserves a little scratch for bringing this to the masses for free.  So do your part and support the community.  It’s an investment in your personal enjoyment of music and an investment in the future development of this software.

BONUS:  How to UPDATE/UPGRADE your Subsonic to the latest version on FreeNAS

From time to time, Subsonic has bug fixes and/or feature additions that may be compelling enough to make you want to upgrade your installation.  I could not find a single shred of information on the internet about how to update the “standalone” version of Subsonic on FreeNAS without completely re-installing.  I did some experimenting and came up with the below solution.  This is not endorsed and certainly should be done at your own risk.  Back-up your Subsonic installation before you try this.

Step 1: Shutdown Subsonic.  In the FreeNAS web interface go to System > Advanced > Command script and then delete following “PostInit” script:

/var/subsonic/standalone/subsonic.sh

Reboot the system.  Subsonic will not automatically run on restart and it will be safe to make changes.

Step 2: Back up your Subsonic installation by copying all files under /var/subsonic to another safe location.  If you for some reason run into an issue during the install, you should be able to simply copy all of these files back and be back in business.

Step 3: Download the latest standalone package here.  Put the new tarball on my FreeNAS share drive so that you can access it via the terminal (i.e. under the /mnt/share-name/path-to/ directory)

Step 4: Unpack subsonic-x.x-standalone.tar.gz to “var/subsonic/standalone”.  Using SSH:

$ cd /var/subsonic/standalone
$ tar xvzf /mnt/share-drive/path-to/subsonic-x.x-standalone.tar.gz

This will unpack the new files right over the top of the old files.  Edit permissions on the new files if desired.

Step 5: Edit the subsonic.sh file as necessary.  (see step 6 above)

Step 6: In the FreeNAS web interface, go to System > Advanced > Command script and add the following “PostInit” script:

sh /var/subsonic/standalone/subsonic.sh

Step 7: Reboot FreeNAS, and go to http://<your-freenas-server>:4040, login and confirm your settings.

Step 8: Enjoy.

I would love to hear your successes or failures to make this tutorial just a bit more useful.  Feedback is always welcome.

11 Responses to “installing subsonic on freenas (and bonus upgrade instructions)”

  1. Gravatar Thomas Says:

    Great deal! Worked out fine. I however got the following packages “on line” before dispersing them into the designated folders and unpacking them there..

    #BASE packages
    pkg-config-0.25_1.tbz
    trans-1.0.4.tbz
    xproto-7.0.10_1.tbz
    xextproto-7.0.2.tbz
    javavmwrapper-2.3.2.tbz
    diablo-jre-freebsd7.i386.1.6.0.07.02.tbz

    #Subsonic
    subsonic-4.0.1-standalone.tar.gz

    #ENCODER packages
    libiconv-1.13.1_1.tbz
    #dependent application:unpackage first
    libogg-1.2.2,4.tbz
    #dependent application:unpackage first
    flac-1.2.1_2.tbz
    lame-3.99.tar.gz
    mac-3.99.4.5_1.tbz

    I however did not get the FLAC encoder to work. Playing now and figuring out odds and in. Do not see where I stream movies. Fun! fun!

    Thanks for this awesome contribution: hands down beat Linuxuser magazine who failed to even suggesting modding the .sh file.

  2. Gravatar alban Says:

    merci

  3. Gravatar nebhead Says:

    je vous en prie

  4. Gravatar nebhead Says:

    Thanks! I appreciate the praise.

  5. Gravatar NickM Says:

    Hello!Thanks for the tutorial!

    one problem though.When starting subsonic i get error “Error occurred during initialization of VM
    Unable to load ZIP library: /usr/local/diablo-jre1.6.0/lib/i386/libzip.so”

    i’ve googled but no luck.any suggestions please?

  6. Gravatar NickM Says:

    I forgot to mention i am using Freenas 0.7.5
    ad Subsonic 4.6

  7. Gravatar nebhead Says:

    I wonder if your Java VM package was installed correctly. Do you remember if you got any error messages when installing your Java packages? Did you remember to run the sentenv command before doing the pkg_add commands? (setenv PACKAGESITE ftp://ftp-archive.freebsd.org/pub/FreeBSD-Archive/ports/i386/packages-7.3-release/Latest/)

  8. Gravatar nebhead Says:

    Or maybe you grabbed the wrong Java package? Check to make sure you’ve got the right one for your build (64-bit or 32-bit, etc.)

  9. Gravatar NickM Says:

    Thanks for the answer

    i had only warnings for having installed versions higher than those that JAVA requires.
    I will try the exact versions as shown in the warnings.

  10. Gravatar dogs Says:

    Hi, just wanted to mention, I liked this post. It was helpful. Keep on posting!

  11. Gravatar EchoDeltaBravo Says:

    Awesome post! I just got my N40L and I’m a bit lazy to work this out myself, haha!

Leave a Reply