Subsonic on Ubuntu Gutsy

Some guys at work were using Jinzora to manage their music collections at home. I tried it out, but found that it was really really buggy and it really didn't like how I have my web server set up at home (Special port + NAT + SSL). Another co-worker found Subsonic, which does basically the same thing, but in a much better way. The biggest downside to Subsonic is that it's java-based, but, that's not that big of a deal.

For whatever reason, I decided to use Subsonic under the Tomcat installation method, so I thought that I'd document how I did that. I used a custom install of the latest tomcat because I couldn't seem to make the tomcat from apt work properly. Additionally, I didn't really like the way that the Ubuntu/Debian Tomcat package was set up. I'd prefer to run Tomcat as a dedicated user, not as a pseudo-one.

1) Install the pre-requisites to making this whole thing work properly:

apt-get install sun-java6-bin sun-java6-jdk sun-java6-jre lame lame-extras libapache2-mod-jk

This will install Java, lame for transcoding and mod_jk for apache. If you already have Java installed somewhere, you can omit it.

2) Create a tomcat user and group and create the subsonic storage directory -

groupadd tomcat
useradd -m -g tomcat

I'd recommend against giving this user a password - you'll never need to login as this user, you can just su to the user when you need to.

Next, create the subsonic directory and assign permissions:

mkdir /var/subsonic
chown tomcat:tomcat /var/subsonic

3) Add JAVA_HOME to your .bashrc:
Add this line to your ~/.bashrc:

JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.03/; export JAVA_HOME

Obviously, you may need to modify this a bit for the location of your java. You may also need to modify your PATH so that 'java' is in it.

4) Become the Tomcat user, download the latest Tomcat 6 release from here, and decompress it.

su - tomcat
wget http://some.url.to.apache/apache-tomcat-version.tar.gz
tar -xvzf apache-tomcat-version.tar.gz

5) Create a user to manage Tomcat. To do this, we'll need to modify the file 'apache-tomcat-version/conf/tomcat-users.xml'. Change the following:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="tomcat"/>
  <role rolename="admin"/>
  <role rolename="role1"/>
  <user username="admin" password="thuperthecret" fullName="" roles="admin,manager,role1,tomcat"/>
</tomcat-users>

5a) You may want to change the port number to reflect the port that Ubuntu/Debian uses by default. You don't have to do this, but, it may make sense if you use other Debian Tomcat stuff. I'm not really sure. Just edit conf/server.xml, and modify the port numbers on lines 67 & 73 (Or just search for 8080) by changing it to 8180.

6) Start up Tomcat and verify you can get to it via a web browser:

su - tomcat
cd ~/
apache-tomcat-version/bin/startup.sh
Using CATALINA_BASE:   /home/tomcat/apache-tomcat-6.0.16
Using CATALINA_HOME:   /home/tomcat/apache-tomcat-6.0.16
Using CATALINA_TMPDIR: /home/tomcat/apache-tomcat-6.0.16/temp
Using JRE_HOME:       /usr/lib/jvm/java-6-sun-1.6.0.03/

Now, in a web browser, enter http://yourhost:8180, and make sure it loads. Next, click the 'Tomcat Manager' link on the main page, and enter the username & password for the management user you created above.

7) Grab the Subsonic WAR file from here. This can be done on your regular PC and doesn't have to be on the server.

8) At the bottom of the Tomcat management section is a section that says 'Deploy'. Click on 'Browse' in the 'WAR File to Deploy' section and navigate to the war file downloaded in step 7. This will deploy the webapp, and the page will reload. Verify that Subsonic is running by looking under the 'Running' column on the page after the reload. If the deployment fails make sure you have /var/subsonic created and tomcat can write to that directory.

9) Log into Subsonic and do the basic setup. Go to http://yourserver:8180/subsonic, login with the default username and password, and add your music collection. Verify basic functionality within Subsonic before putting Tomcat behind Apache.

10) Assuming Subsonic works as expected, now it's time to set up mod_jk to redirect requests from Apache to Subsonic. (This is completely optional, but I'm doing it so that everything is accessible through a single remote port)

Enable mod_jk:

a2enmod jk

Create the file as follows in /etc/apache2/conf.d/mod_jk.conf

JkWorkersFile /etc/apache2/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile     /var/log/apache2/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile     /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

Create the Tomcat workers file in /etc/apache2/workers.properties with the following content:

# Define 1 real worker using ajp13
worker.list=subsonic
# Set properties for subsonic (ajp13)
worker.subsonic.type=ajp13
worker.subsonic.host=localhost
worker.subsonic.port=8009

11) I intended on having this work on all of my Apache ports, so I created a conf file in conf.d instead of adding to a VirtualDomain. This is mostly being done because of the way MythWeb mangles URL's and avoiding that.

Create the configuration file as follows in /etc/apache2/conf.d/subsonic.conf

Alias /subsonic /var/www/apache2-default
JkMount /subsonic/* subsonic

Note - Even though I'm aliasing it, it'll never get used. Again, this is to simply bypass the way that MythWeb mangles URL's, so you may not need it.

12) Restart Apache and correct any errors that may arise.

13) Visit http://yourwebsite/subsonic and you should be able to see subsonic through apache!