Monday, December 20, 2010

Installing Mediatomb on Solaris 11 Express

My home NAS is now running Solaris 11 for the 'express' purpose (sorry) of being able to use ZFS, and all the light, joy and happiness it brings to the world of storage. I'm using three 1TB SATA disks in a RAIDZ configuration, and using ZFS's built-in filesystem compression, CIFS and NFS sharing capabilities. Since I use a PS3 as my media center front-end I need a DLNA/UPnP media server and having used Mediatomb previously on Linux, that's what I'll walk through installing from source here today.

Before starting, make sure you have GNU C compiler (gcc) and make installed. This is easily achieved using the new package management tools in Solaris 11. Try man pkg to get started.

For Mediatomb to correctly identify certain files' MIME types (like image/jpeg, for example) you need to build the GPL'd version of the file utility for a library called libmagic.
tar zxvf file-5.04.tar.gz
cd file-5.04
./configure --prefix=/usr/local
make
make install
Check for libmagic library and headers:
ls /usr/local/include
ls /usr/local/lib
Next, download the source for Mediatomb and extract it.
tar zxvf mediatomb-0.12.1.tar.gz
cd mediatomb-0.12.1
The source code contains some apparently outdated prelink logic which breaks the build on newer versions of the OS, so we need to comment it out. You can either edit src/main.cc by hand or just use the following patch - save it to main.cc.patch0.
*** src/main.cc.orig    2010-12-20 13:13:11.080796210 +1000
--- src/main.cc 2010-12-20 13:13:30.478542756 +1000
***************
*** 141,146 ****
--- 141,147 ----

      Ref<Array<StringBase> > addFile(new Array<StringBase>());

+ /*
  #ifdef SOLARIS
      String ld_preload;
      char *preload = getenv("LD_PRELOAD");
***************
*** 155,160 ****
--- 156,162 ----
          exit(EXIT_FAILURE);
      }
  #endif
+ */

  #ifdef HAVE_GETOPT_LONG
      while (1)
And apply the patch:
patch src/main.cc < main.cc.patch0
Now configure, build and install:
./configure --enable-libmagic --with-magic-h=/usr/local/include --with-magic-libs=/usr/local/lib
make
make install
At this stage, you could add your config files and fire up the daemon, however I'm going to create service manifests so we can manage startup and shutdown of Mediatomb via the Solaris Service Management Framework (SMF). Save this file as /lib/svc/method/svc-mediatomb.
#!/bin/sh
. /etc/mediatomb.conf
LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/mediatomb -d \
    -u $MT_USER \
    -g $MT_GROUP \
    -P $MT_PIDFILE \
    -l $MT_LOGFILE \
    -m $MT_HOME \
    -f $MT_CFGDIR \
    -p $MT_PORT \
    -e $MT_INTERFACE \
    $MT_OPTIONS
Create /etc/mediatomb.conf, setting appropriate values for variables above. Something like the following would suffice:
MT_INTERFACE="rge0"
MT_OPTIONS=""
MT_PORT="50500"
MT_USER="media"
MT_GROUP="media"
MT_PIDFILE="/var/run/mediatomb.pid"
MT_LOGFILE="/var/log/mediatomb"
MT_HOME="/etc"
MT_CFGDIR="mediatomb"
Now for the service manifest - create this file as /var/svc/manifest/application/mediatomb.xml.
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type="manifest" name="mediatomb">
    <service name="application/mediatomb" type="service" version="1">
        <create_default_instance enabled="false"/>
        <single_instance/>
        <dependency name="network" grouping="require_all" restart_on="error" type="service">
            <service_fmri value="svc:/milestone/network:default"/>
        </dependency>
        <dependency name="filesystem" grouping="require_all" restart_on="error" type="service">
            <service_fmri value="svc:/system/filesystem/local"/>
        </dependency>
        <exec_method type="method" name="start" exec="/lib/svc/method/svc-mediatomb" timeout_seconds="60">
        </exec_method>
        <exec_method type="method" name="stop" exec=":kill" timeout_seconds="5">
        </exec_method>
        <property_group name="startd" type="framework">
            <propval name="ignore_error" type="astring" value="core,signal"/>
        </property_group>
        <stability value="Evolving"/>
        <template>
            <common_name>
                <loctext xml:lang="C">
                    UPnP Media Server
                </loctext>
            </common_name>
            <documentation>
                <manpage title="mediatomb" section="1" manpath="/opt/local/share/man"/>
                <doc_link name="mediatomb.cc" uri="http://mediatomb.cc"/>
            </documentation>
        </template>
    </service>
</service_bundle>
Then validate, import and run the service:
svccfg validate /var/svc/manifest/application/mediatomb.xml
svccfg import /var/svc/manifest/application/mediatomb.xml
svcs -a mediatomb
svcadm enable mediatomb
If all went well you should now be able to connect to the Mediatomb web interface on port 50500.

7 comments:

  1. Hi Jason

    Thank you for your post. Can you please help me with my installation.

    I installed the live cd version of Oracle Solaris 11 Express and followed your Mediatomb installation steps but got some issues.


    These are my steps until I ran into difficulty.


    1. I installed gcc like: pkg install gcc-3
    2. make was up to date
    3. I got the libmagic file utility library from: wget ftp://ftp.astron.com/pub/file/file-5.04.tar.gz
    ...and followed your instructions.
    4. I got mediatomb from: wget http://sourceforge.net/projects/mediatomb/files/MediaTomb/0.12.1/mediatomb-0.12.1.tar.gz
    ...and followed your instructions

    4a. I had to change the directory, cd ../mediatomb-0.12.1 'to' cd /mediatomb-0.12.1

    5. For the patch, I did: touch mediatomb-0.12.1/src/main.cc.patch0
    5a. vi touch mediatomb-0.12.1/src/main.cc.patch0
    ...and copy and paste your patch.

    6. After I applied the patch
    6a. I did: ./configure --enable-libmagic --with-magic-h=/usr/local/include --with-magic-libs=/usr/local/lib

    CONFIGURATION SUMMARY ----

    sqlite3 : yes
    mysql : missing
    libjs : missing
    libmagic : yes
    inotify : missing
    libexif : yes
    id3lib : disabled
    taglib : missing
    libmp4v2 : missing
    ffmpeg : missing
    ffmpegthumbnailer : missing
    lastfmlib : missing
    external transcoding : yes
    curl : yes
    YouTube : yes
    libextractor : disabled
    db-autocreate : yes

    Are the missing items required and if so how do I install them?

    Thank you
    Neil

    ReplyDelete
  2. Hi Neil

    You don't need to worry about the missing items in the configuration summary, they won't affect the build.

    It looks like the patch has failed somehow as the error below appears to be the compiler unable to parse the C++ code. Can you please re-extract the archive (restore main.cc) and manually comment out the section that begins with:

    #ifdef SOLARIS
    ...
    #endif

    Using C-style comments (/* ... */).

    Thanks, let me know how you go.

    Jason

    ReplyDelete
  3. Hi Jason

    After editing main.cc, I was able to continue and complete the installation.

    I wasn't able to connect to Mediatomb.

    Since I'm using the desktop version I went ahead and installed apache, (pkg install apache-22) but still couldn't connect ip:50500.

    Help please.

    ReplyDelete
  4. Instructions are very helpful, but I did run into a couple of issues. Assuming that we have a clean install of OSE 11 (like mine), users will need to run through some additional steps to get everything working.

    Permissions for /lib/svc/method/svc-mediatomb need to be setup properly:
    chmod 755 /lib/svc/method/svc-mediatomb

    Setup proper ownership of /lib/svc/method/svc-mediatomb
    chown root:bin /lib/svc/method/svc-mediatomb

    The manpath in the /var/svc/manifest/application/mediatomb.xml should be:


    Also I changed the running user from "media" to "nobody". By default there is no "media" user unless you create it.

    Update the config file /etc/mediatomb.conf usernames:
    MT_USER="nobody"
    MT_GROUP="nobody"

    Update permissions for the configuration files:
    chown nobody:nobody -R /etc/mediatomb*

    ReplyDelete
  5. Correction to the above


    The manpath in the /var/svc/manifest/application/mediatomb.xml should be:
    /usr/local/share/man

    ReplyDelete
  6. Excellent instructions Jason. I seem to have an issue where running the service puts it in to a maintenance state. If I run it in a console manualy it appears to run just fine. I've tried changing the configuration file to reflect various users/groups with the same result.

    Any help would be greatly appreciated.

    ReplyDelete
  7. Thanks for the instructions Jason and the additions Jerry, I've found another small problem with the configure of mediatomb, when running I received the errors...

    configure: WARNING: unrecognized options: --with-magic-h, --with-magic-libs
    configure: WARNING: your magic library is broken, if you are using Slackware install the 'file' package manually

    After a quick read of the 'configure' script it looks like the options have changed, ran ok with...

    ./configure --enable-libmagic --with-libmagic-h=/usr/local/include --with-libmagic-libs=/usr/local/lib

    Now streaming meda to my new Humax PVR ;-)

    ReplyDelete