Software Engineer

mediatomb on centos 5

· by jsnby · Read in about 4 min · (786 Words)
Computers

It’s 9:36PM on a Monday night. For the past few weeks, I’ve been picking up our son from daycare and getting home about an hour before my wife. During that time, I like to crank up some tunes on our home stereo receiver. The problem is that my server and my pc are about 25 feet away from my receiver. I was plugging a long headphone extension cord with a headphone to RCA splitter into the front of the reciever, but our son is on the verge of crawling and I don’t wany any extra or unnecessary cables to be within his reach.

We have a PS3 hooked up to our receiver already. It’s plugged into my network. All of my music and media files are on my CentOS 5.5 server. Let’s install a DLNA server!

There are a ton of DLNA servers out there, but I decided on giving MediaTomb a shot. I was also considering uShare, but since active development has been suspended at this time, I decided to stick with MediaTomb.

Ok…now it’s 9:40PM. Let’s find out if we need to build this from source or not:

$ sudo yum search mediatomb
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: mirror.5ninesolutions.com
 * base: mirrors.netdna.com
 * epel: mirrors.solfo.com
 * extras: mirrors.netdna.com
 * rpmforge: apt.sw.be
 * updates: mirrors.versaweb.com
======= Matched: mediatomb ========================================
mediatomb.x86_64 : MediaTomb - UPnP AV Mediaserver for Linux

It looks like it’s in the epel repo. Cool! Let’s start by setting up a skeleton puppet module(/etc/puppet/modules/mediatomb/manifests/init.pp):

class mediatomb {
    package { "mediatomb":
        ensure => latest,
    }
}

Added an import to my /etc/puppet/manifests/site.pp:

And then added an include to the node definition for my server:

include mediatomb

Then I ran puppet once manually:

$ sudo /usr/sbin/puppetd --onetime --no-daemonize --verbose --no-splay

Now, let’s move on to configuration. I want mediatomb to run on eth0. I modified my puppet manifest to now look like this:

class mediatomb {
    package { "mediatomb":
        ensure => latest,
    }

    file { "/etc/mediatomb.conf":
        ensure  => present,
        source  => "puppet:///modules/mediatomb/mediatomb.conf",
        owner   => root,
        group   => root,
        mode    => 644,
        require => Package["mediatomb"],
        notify  => Service["mediatomb"],
    }

    service { "mediatomb":
        ensure     => running,
        enable     => true,
        hasrestart => true,
        hasstatus  => true,
    }
}

Then, I copied /etc/mediatomb.conf to /etc/puppet/modules/mediatomb/files/mediatomb.conf. I then updated that file and changed MT_INTERFACE="NOT_SET" to MT_INTERFACE="eth0".

And ran puppet again manually. It’s now 9:55PM. Let’s check and see if it’s actually running:

$ sudo /etc/init.d/mediatomb status
mediatomb (pid  19966) is running...
# And listening:
$ netstat -an | grep 50500
tcp        0      0 0.0.0.0:50500               0.0.0.0:*                   LISTEN

Checking the log file, it looks like it’s configured to use sqlite out of the box….from /var/log/mediatomb:

2011-04-11 21:55:11 WARNING: Sqlite3 database seems to be corrupt or doesn't exist yet.
2011-04-11 21:55:11    INFO: no sqlite3 backup is available or backup is corrupt. automatically creating database...
2011-04-11 21:55:11    INFO: database created successfully.

I’m more of a MySQL guy myself. The database connection info is specified in /etc/mediatomb/config.xml. Copy this into the files directory of your puppet module, then let’s edit it:

cp /etc/mediatomb/config.xml /etc/puppet/modules/mediatomb/files/

Open it up and modify the storage section:

Before:

<storage>
  <sqlite3 enabled="yes">
    <database-file>mediatomb.db</database-file>
  </sqlite3>
  <mysql enabled="no">
    <host>localhost</host>
    <username>mediatomb</username>
    <database>mediatomb</database>
  </mysql>
</storage>

After:

<storage>
  <sqlite3 enabled="no">
    <database-file>mediatomb.db</database-file>
  </sqlite3>
  <mysql enabled="yes">
    <host>localhost</host>
    <username>mediatomb</username>
    <database>mediatomb</database>
    <password>PASSWORD</password>
  </mysql>
</storage>

Add a file resource to your puppet manifest:

    file { "/etc/mediatomb/config.xml":
        ensure  => present,
        source  => "puppet:///modules/mediatomb/config.xml",
        owner   => root,
        group   => root,
        mode    => 644,
        require => Package["mediatomb"],
        notify  => Service["mediatomb"],
    }

Now, log into mysql and create the database and grant the permissions. At this point, I don’t know the exact permissions that the mediatomb user will require, so grant all permissions only on this database. We’ll try to revisit this later and restrict it to the minimum set of permissions:

$ mysql -u root -p
mysql> CREATE DATABASE mediatomb;
Query OK, 1 row affected (0.02 sec)

mysql> GRANT ALL PRIVILEGES ON mediatomb.* TO 'mediatomb'@localhost IDENTIFIED BY 'PASSWORD';
Query OK, 0 rows affected (0.05 sec)

Now it’s 10:09PM. Let’s try to add some data. In the config.xml, modify the import section. My music is stored under /some/path/to/the/media:

Modify this:

<import hidden-files="no">
<scripting script-charset="UTF-8">
  <common-script>/usr/share/mediatomb/js/common.js</common-script>
  <playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script>
  <virtual-layout type="builtin">
    <import-script>/usr/share/mediatomb/js/import.js</import-script>
  </virtual-layout>
</scripting>
<mappings>

To this:

<import hidden-files="no">
<scripting script-charset="UTF-8">
  <common-script>/usr/share/mediatomb/js/common.js</common-script>
  <playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script>
  <virtual-layout type="builtin">
    <import-script>/usr/share/mediatomb/js/import.js</import-script>
  </virtual-layout>
</scripting>
<autoscan use-inotify="auto">
    <directory location="/some/path/to/the/media" mode="timed" interval="3600" level="full" recursive="yes" hidden-files="no"/>
</autoscan>
<mappings>

Then re-run puppet. I did a quick spot-check of the database and it appeared that all of my music was there:

$ mysql -u root -p
mysql> use mediatomb;
Database changed
mysql> show tables;
+---------------------+
| Tables_in_mediatomb |
+---------------------+
| mt_autoscan         |
| mt_cds_active_item  |
| mt_cds_object       |
| mt_internal_setting |
+---------------------+
4 rows in set (0.00 sec)

mysql> select count(*) FROM mt_cds_object;
+----------+
| count(*) |
+----------+
|    51391 |
+----------+
1 row in set (0.01 sec)

So, now what? It’s 10:25PM. We have a puppet module, mediatomb is running against a MySQL database and it appears that it has correctly imported all of my music. Let’s fire up the PS3 and see if it shows up….It’s there under both the Audio and Video sections of the PS3 UI.

More config tweaks…since I have data stored on my disk the way I want it presented to me, I turned off the virtual containers by modifying my config.xml:

<virtual-layout type="disabled">

I turned off the UI:

<ui enabled="no">

I ended up stopping mediatomb, dropping the database, creating the database, then restarting both mediatomb and the PS3. Pulled up the UI. I then browsed to my music, selected a song and hit play, rolled up the 25 foot headphone cord and put it back into storage.

Cheers!