Tuesday, September 6, 2011

Coherence and Gallery3

Spent a few days playing with DLNA and WebDAV services. Ended up focusing on Gallery3 and Coherence. Wrote a start-up script for Coherence and developed a work-around to get Coherence to work with Gallery3.

Coherence

Wrote a start-up script for Coherence, based on the skeleton script found in /etc/init. Not too many changes were required:

 1) I moved /root/.coherence to /etc/coherence/coherence.conf
 
 2) Edited the startup script so that:

 DESC="Coherence UPnP service"
 NAME=coherence
 DAEMON=/usr/bin/$NAME
 DAEMON_ARGS=" -c /etc/coherence/coherence.conf"
 
 3) I then added "-b" to the start-stop-daemon lines in "do_start" and  removed "--pidfile $PIDFILE" from all lines in do_start() and  do_stop().

The addition of "-b" causes start-stop-daemon to move coherence to the background, once it's started. Without, Coherence never releases control back to the system (you'd continuously see the output of Coherence and the boot sequence would never reach the login prompt). (Hint: hit Control-C if you manage to do this.)

Removal of "--pidfile $PIDFILE" is more of a personal choice. If you want to continue to use PIDs, leave "--pidfile $PIDFILE" in and add "-m" to the line. "-m" forces the start-up script to create a PID for Coherence because Coherence isn't written to return a PID to the start-up script. This works fine as long as you never run the start-up script while the service is already running. If you do this, a new PID is created that has nothing to do with the currently running service (i.e., you won't be able to stop Coherence with "service coherence stop").

Removing "--pidfile $PIDFILE" forces the script to act more like the "kill" function, where the start-up script looks for functions with the same name as itself and "kill -15"s the process. It's less elegant, but Coherence doesn't have a shutdown function so the two methods are more or less equivalent.

In any case, my version of the start-up script is here.

Coherence and Gallery3

Coherence has a few modules, one of which allows you to show Gallery2-hosted graphics on your UPnP-enabled media player. Notice that I've said "Gallery2". Apparently, it plays nicely with Coherence. Unfortunately, some time in the past, I decided to be "cutting edge", installed Gallery3, and uploaded close to 500 pictures into it.

The problem with Gallery3 is that it's still in development and only recently acquired the Gallery_Remote module which allows Gallery2 to work with Coherence. I spent a few hours experimenting with Gallery_Remote, trying to get it to function. It appears to be very version specific and won't work with my build of Gallery3. At this point, I went looking for work-arounds.

My work-around idea involved setting up WebDAV so that Coherence and using davfs2 to trick Coherence into believing that it was serving files from a local dircectoy. A quick search of Gallery3 modules revealed that it did have a WebDAV module (one based on SabreDAV). I was somewhat successful in getting it to run but, for some reason, it refuses to serve up the first folder of pictures in the directory (works well with all others). Finding this unsuccessful, I removed the module.

My next approach was to use the DAV module that's built into Apache2. This turned out to be the proper approach. I used Adam Shand's notes in configuring Apache2. The only thing that Adam doesn't mention is that you need to run a2enmod for dav, dav_fs, and dav_lock. My version of the Apache2 configuration is here.  Drop it in /etc/apache2/conf.d and restart Apache.

After that, mounting the WebDAV folder is quite easy. It is the same approach that I employed to get Knowledgetree to work as file storage for the in-house wiki. You only have to add a line to /etc/davfs2/secrets (e.g., "http://192.168.2.144/gallery-dav tim pAsSwOrD") and a line to /etc/fstab (e.g., "http://192.168.2.144/gallery-dav /var/www/gallerydav davfs rw,user,auto 0 0"). See the man page for davfs2 for more details.

After all of that work, I now have a media server which can supposedly speak to my wife's TV and my son's PS3. It's configured to serve up: music via Ampache, family photos via Gallery3, movie trailers from Apple iTunes, and streams from various Shoutcast stations. Keeping the service will probably be based on my wife's and son's reactions as the interface is a bit to rigid for my use (I prefer more flexibie solutions like Savonet).