Monday 2 January 2006

Make your own Linux iTunes Server

Make your own Linux iTunes Server

This walkthrough is based on Fedora Core 3 which I'm running on my MythTV Server. If you find any innaccuracies, please let me know and I'll fix 'em.

Install daapd using APT

Make sure you have Dag's repository set up for apt (you might wish to set up a Yum repo instead as Yum is included by default with Fedora).

My repo file looks like this...

# cat /etc/apt/sources.list.d/dries.list
rpm http://apt.sw.be dries/fedora/fc3/i386 dries
rpm-src http://apt.sw.be dries/fedora/fc3/i386 dries

Make sure you are up to date then get the daapd package, the howl package (needed for mDNSRepsonder) and their depencencies...

# apt-get update
# apt-get dist-upgrade
# apt-get install daapd
# apt-get install howl

Configuration

Create a config file like this one

# cat /etc/daapd.conf
Port            3689
ServerName      MythMusic
DBName          daapd music
Password
Root            /av/audio
Cache           /var/spool/daapd/cache
Timescan        2
Rescan          0

Change /av/audio to the location of your music collection, and create the folder /var/spool/daapd/cache as root (if you don't do this, the files will be rescanned by the server each time you run daapd). If you want to secure your audio files, put a password in the obvious gap.

Start daapd as a Service

Create a file called /etc/rc.d/init.d/daapd with the following contents

# cat /etc/init.d/daapd
#!/bin/sh
#
# A startup script for the daapd DAAP server
#
# chkconfig: 345 98 2
# description: This script is used to start the daapd \
# server as a background process.\
#
# Usage /etc/init.d/daapd start|stop|reload|restart|status

# Source function library.
. /etc/rc.d/init.d/functions

DAAP_CONF=/etc/daapd.conf
DAAP_LOG=/var/log/daapd/access_log
prog=DAAP
exe=/usr/bin/daapd

start() {
        echo -n "Starting $prog: "
        if [ -f /var/lock/subsys/daapd ] ; then
                echo_failure
                echo
                exit 1;
        fi
        daemon $exe -c $DAAP_CONF >> $DAAP_LOG &
        RETVAL=$?
        [ $RETVAL = 0 ] && touch /var/lock/subsys/daapd && echo_success
        echo
        return $RETVAL
}

stop() {
        echo -n "Stopping $prog: "
        killproc $exe
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/daapd /var/run/daapd.pid
}

reload()
{
        echo -n $"Reloading $prog:"
        killproc $exe -HUP
        RETVAL=$?
        echo
}


case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $exe
        RETVAL=$?
        ;;
*)
        echo "Usage: daapd {start|stop|reload|restart|status}"
        exit 1
esac

Create the log folder so that the service can write a log file.

# mkdir -p /var/log/daapd

Now you should be able to start daapd as a service...

# service daapd start
Starting DAAP:              [  OK  ]

It may be some time before you can access this service if you have a large collection, as it will not respond until it has indexed the files.

mDNSResponder Configuration

In order for iTunes to detect the new playlists, you need to setup mDNSResponder to broadcast the presence of the service. Add the following line to the end of the mDNSResponser config file.

# tail -1 /etc/howl/mDNSResponder.conf
MythMusic _daap._tcp.     local.  3689

Start mDNSResponder

# service mDNSResponder start
Starting mDNSResponder...   [  OK  ]

Any copies of iTunes residing on your local network should now have a shared music folder containing your entire music collection, including any playlists found in the same folder.

No comments:

Post a Comment