Featured Post

HOW TO: Install VPN server on Ubuntu when server is behind firewall

The whole point in this post is to run your own VPN service, and allow you to connect remote devices to your home network. To start off yo...

Apr 13, 2013

Installing Subsonic Server on NAS4Free (embedded)

Firstly, I have to say I cannot take all the credit for this... I got a lot of information from http://lameguy.wordpress.com, who in turn got it from NAS4Free wiki.

However, I did find some problems along the way, and as usual I want to keep it somewhere I can get easy access to in future - this blog.  Please also note, this will solve any m4a and flac transcoding issues, and possibly other codecs.

The whole process relies on you setting up a jail in NAS4Free so that the changes are not lost on reboot (since this is an embedded guide).

Lets start of with configuring NAS4Free to complete this task:

 

Configuring NAS4Free

  1. Go to this page: http://wiki.nas4free.org/doku.php?id=documentation:setup_and_user_guide:services_ssh
  2. Check so that ssh is enabled and check the port number and also check that the option “Permit root login”is enabled.(The root password is the same as the WebGUI password but the login name is always “root”)
  3. Go to the NAS4Free webgui and navigate the menu like this: System->Advanced->sysctl.conf
    Add there:
    Name: security.jail.chflags_allowed
    Value: 1
    Comment: can be whatever you want.
  4. Now navigate in the webgui like this: Advanced|File Editor
  5. In the file path textbox write “/etc/rc.conf”
  6. Click load
  7. Add to the file jail_enable=”yes”
  8. Click the save button next to the textbox where you wrote the path to the file and then restart the NAS4Free server.

 

Create Folders and Mount Points

SSH into your NAS4Free box using putty or similar. NOTE: Change all reference to /mnt/data to the mountpoint on your NAS where you are going to store the jail.
  • mkdir /jail
  • mkdir /mnt/data/jail
  • mkdir /mnt/data/jail/{work,proto,conf}
  • mount_nullfs /mnt/data/jail /jail

 

Download and Extract FreeBSD Base System

The base system has to be downloaded to make sure you get all the necessary binaries, config files and scripts. To download it you can just copy paste the following commands into the ssh shell.
  • cd /jail/work
  • fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/`uname -m`/`uname -m`/`uname -r | cut -d- -f1-2`/base.txz
  • fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/`uname -m`/`uname -m`/`uname -r | cut -d- -f1-2`/lib32.txz
The last command for fetching lib32 is not needed if you are running NAS4Free on an 32bit system.  The following two commands extract the base system into the proto folder inside the jail.
  • tar xvf /jail/work/base.txz -C /jail/proto/
  • tar xvf /jail/work/lib32.txz -C /jail/proto/

 

Installing the Plugins Jail Binaries

  • cd /jail
  • mkdir -p conf/root/{etc/rc.d/,usr/bin,usr/sbin}
  • cp proto/etc/rc.d/jail conf/root/etc/rc.d/
  • cp proto/usr/sbin/{jail,jexec,jls} conf/root/usr/sbin/
  • cp proto/usr/bin/mktemp conf/root/usr/bin/

 

Configuring the Jail

NOTE: Obviously exchange EST for your own time=zone. Next we will configure the mounts that the jail is going to be able to access.  
  • cp /etc/resolv.conf /jail/proto/etc/
  • cp /jail/proto/usr/share/zoneinfo/EST /jail/proto/etc/localtime
NOTE: Change DataDisk1 for the mounts that you have on the NAS that you want to be accessible in the jail.
  • touch /jail/conf/fstab.proto
  • mkdir /jail/proto/mnt/DataDisk1
  • nano /jail/conf/fstab.proto
Copy into the fstab file the following lines:

/mnt/data/DataDisk1 /jail/proto/mnt/DataDisk1 nullfs rw 0 0

The drive is mounted read write for playlist, comments, ratings, podcast access from Subsonic.

The next part of the configuration is to create the rc.conf file.

  • touch conf/rc.conf.local
  • nano conf/rc.conf.local
Copy into the rc.conf.local the following lines:

jail_enable="YES" # enable jails YES|NO
jail_list="proto" # name of the jails to start “proto www…”
jail_proto_rootdir="/jail/proto" # path to our jail
jail_proto_hostname="proto" # hostname
jail_proto_ip="192.168.0.30" # ip of the jail, replace with a ip in the same subsystem as your NAS
jail_proto_interface="re0" # Network Interface to use, replace with your NAS interface name
jail_proto_devfs_enable="YES" # use devfs
jail_proto_mount_enable="YES" # mount YES|NO
jail_proto_fstab="/jail/conf/fstab.proto" # File with Filesystems to mount 

Create the Jail Start-up Script

  • nano /jail/conf/jail_start
Copy into jail_start the following lines:

#!/bin/tcsh -x
#mounting to /jail
mkdir /jail
mount_nullfs /mnt/data/jail /jail
# copy jail binaries to /usr, not needed if N4F is 454 or up
# because Daoyama include needed files, uncomment if you use low .454 version
# cp -r /jail/conf/root/ /
# link config files to /etc
ln -s /jail/conf/rc.conf.local /etc
#start all jails
/etc/rc.d/jail start

Make the start-up script executable with the following command:
  • chmod 755 /jail/conf/jail_start
And to make it run each time the NAS server is started, add the following via the webgui under System|Advanced|Command Scripts.

Command: /mnt/data/jail/conf/jail_start
Type: PostInit

Save and apply, and reboot your server. After a successful reboot check your new jail via SSH using the jls command, you should see something like this:

JID             IP Address                   Hostname                      Path
1                192.168.1.201             proto                              /jail/proto

And that’s how you setup a FreeBSD jail on NAS4Free embedded.


Install Subsonic and Required Packages

Enter the jail with the following command (based on the output of example jls above we use 1):
  • jexec 1 csh
The pkg_add command doesn’t function properly inside the jail. To fix this you have to run the following command NOTE: I am using a 64-bit install:
  • setenv PACKAGESITE ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-9.1-release/Latest/
Now start installing the packages required by Subsonic:
Now install libmp3lame so that ffmpeg can use it for transcoding:
  • pkg_add -r -v wget
  • wget http://downloads.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Flame%2Ffiles%2Flame%2F3.98.4%2F&ts=1366036375&use_mirror=superb-dca2
  • tar -xf lame-3.98.4.tar.gz
  • cd lame-3.98.4
  • ./configure
  • make
  • make install clean
Now compile and install your own ffmpeg with libmp3lame enabled, (remember --enable-libmp3lame during make config):
  • portsnap fetch extract
  • cd /usr/ports/multimedia/ffmpeg
  • make config 
  • make install clean  

 

Create Folders and Unpack Subsonic 

Create the folders and download/extract subsonic standalone.
  • mkdir -p /var/subsonic/transcode
  • mkdir /var/subsonic/standalone
  • cp /usr/local/bin/lame /var/subsonic/transcode/
  • cp /usr/local/bin/flac /var/subsonic/transcode/
  • cp /usr/local/bin/ffmpeg /var/subsonic/transcode/
  • cd /tmp/
  • fetch http://heanet.dl.sourceforge.net/project/subsonic/subsonic/4.8/subsonic-4.8-standalone.tar.gz
  • tar xvzf /tmp/subsonic-4.7-standalone.tar.gz -C /var/subsonic/standalone
  • chmod 777 *.*
Enter the following command while you are still inside the jail to see if subsonic starts.
  • sh /var/subsonic/standalone/subsonic.sh
If subsonic started as it should you can connect to it via the browser at the following adress: Jail-IP:4040, default username is admin, and password admin.

Automated Start-up

To make it run each time the NAS server is started add via the webgui under: System|Advanced|Command Scripts.

Command: jexec 1 /var/subsonic/standalone/subsonic.sh
Type: PostInit

Save and apply, and reboot your server. After a successful reboot you can check your Subsonic install via http://Jail-IP:4040

If your Subsonic installation has problems with the audio (the java install couldn’t see your audio dev) install alsa-plugins via the following command:
  • pkg_add -v -r alsa-plugins
ENJOY!

And if you want to access your new service on your android device, why not try out the official Subsonic Music Streamer

(4/17/2013 Updated for Subsonic 4.8)
(5/10/2013 Updated based on fsbruva's comments http://forums.nas4free.org/viewtopic.php?f=79&t=3166&p=19759#p19759)
Post a Comment