Mediatomb on Ubuntu - init script

CycloniteCyclonite Tampa, Florida Icrontian
edited November 2008 in Science & Tech
I'm hopin' one of you linux gods can help me here. I don't profess to know what I'm doing in Linux. I've tried a couple different distros at different points in my life, and right now I'm using Ubuntu 7.10.

I installed Mediatomb using the instructions from their website for the Feisty install. After installing, I prepped the config.xml and launched the server. It worked great. I can browse to the WebUI and add the directories. My PS3 recognizes it and the music streams just fine.

Now on to my problem. I want this to run at startup as a service (daemon?), so I took a look around and found I have to use an init script. One is included when you install Medatomb, and it's already placed in /etc/init.d. So I take a look at it and alter the required settings. My issue comes when it tries to run at startup. At first it was giving me the UPnp Error -117 referenced in the documentation on the site. SO I decided to follow the instructions:
4.1. Network Setup

Some systems require a special setup on the network interface. If MediaTomb exits with UPnP Error -117, or if it does not respond to M-SEARCH requests from the renderer (i.e. MediaTomb is running, but your renderer device does not show it) you should try the following settings (the lines below assume that MediaTomb is running on a Linux machine, on network interface eth1):

# route add -net 239.0.0.0 netmask 255.0.0.0 eth1
# ifconfig eth1 allmulti

Those settings will be applied automatically by the init.d startup script.

The init script adds this when you specify an interface in /etc/default/mediatomb. This is where my next problem comes in: It gives me an error saying it cannot find the specified interface. Specifically, eth1. This is the interface my network cable is connected to, and it has an IP address.

I assumed the interface may not have been fully up yet, so I tried to delay the script startup. I'm not sure if I was successful in delaying it, but either way, I still get the error.

I tried specifying the loopback interface "lo" for the init script, and the server starts up without a hitch. Obviously that doesn't help me share files, but maybe it'll help someone point me in the right direction.

Thanks in advance for your help. I can provide any output you may need. You might have to tell me how to get it though. :)

Comments

  • beatzbeatz i am a hamburger Member
    edited February 2008
    I am no linux god, but'll try to help.

    I am not sure, if I understand you right, but did you edit the init script directly? That is not a good thing. All settings should be made in /etc/default/mediatomb.

    Do you get the error messages at boot or when you issue "/etc/init.d/mediatomb start" at the command line?
  • CycloniteCyclonite Tampa, Florida Icrontian
    edited February 2008
    I had to make one modification to the init script because the startup command was missing a switch for the home directory.

    And I forgot to mention that, sorry. If I run "/etc/init.d/mediatomb start" from the command line, it works fine as well.

    When I get home tonight, I'll post my init script and the other related files.
  • CycloniteCyclonite Tampa, Florida Icrontian
    edited February 2008
    Okay. Here we go.

    Init script:
    #! /bin/sh 
    #
    # MediaTomb initscript
    #
    # Original Author: Tor Krill <tor@excito.com>.
    # Modified by:     Leonhard Wimmer <leo@mediatomb.cc>
    #
    #
    
    ### BEGIN INIT INFO
    # Provides:          mediatomb
    # Required-Start:    $all
    # Required-Stop:     $all
    # Should-Start:      $all
    # Should-Stop:       $all
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: upnp media server
    ### END INIT INFO
    
    
    set -e
    
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DESC="upnp media server"
    NAME=mediatomb
    DAEMON=/usr/bin/$NAME
    PIDFILE=/var/run/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME
    USER=mediatomb
    GROUP=mediatomb
    LOGFILE=/var/log/mediatomb
    HOME=/user/bryan/mediatomb
    
    # Read config file if it is present.
    if [ -r /etc/default/$NAME ]
    then
    	. /etc/default/$NAME
    fi
    
    # if NO_START is set, exit gracefully
    [ "$NO_START" = "yes" ] && exit 0
    
    D_ARGS="-c /etc/mediatomb/config.xml -d -u $USER -g $GROUP -m $HOME -P $PIDFILE -l $LOGFILE"
    
    if [ "$INTERFACE" != "" ] ; then
        D_ARGS="$D_ARGS -e $INTERFACE"
    fi
    
    
    
    # Gracefully exit if the package has been removed.
    test -x $DAEMON || exit 0
    
    #
    #       Function that starts the daemon/service.
    #
    d_start() {
    	touch $PIDFILE
    	chown $USER:$GROUP $PIDFILE
    	touch $LOGFILE
    	chown $USER:$GROUP $LOGFILE
            start-stop-daemon --start --quiet --pidfile $PIDFILE \
                    --exec $DAEMON -- $D_ARGS $DAEMON_OPTS
    }
    
    #
    #       Function that stops the daemon/service.
    #
    d_stop() {
            start-stop-daemon --stop --signal 2 --retry 5 --quiet --pidfile $PIDFILE \
                    --name $NAME
            rm $PIDFILE
    }
    
    #
    #       Function that sends a SIGHUP to the daemon/service.
    #
    d_reload() {
            start-stop-daemon --stop --quiet --pidfile $PIDFILE \
                    --name $NAME --signal 1
    }
    
    case "$1" in
      start)
            echo -n "Starting $DESC: $NAME"
            if [ "$INTERFACE" != "" ] ; then
                # try to add the multicast route
                /sbin/route add -net 239.0.0.0 netmask 255.0.0.0 $INTERFACE  >/dev/null 2>&1 || true
    	fi
            d_start
            echo "."
            ;;
      stop)
            echo -n "Stopping $DESC: $NAME"
            d_stop
            echo "."
            ;;
      reload|force-reload)
            echo -n "Reloading $DESC configuration..."
            d_reload
            echo "done."
      	;;
      restart)
            #
            #       If the "reload" option is implemented, move the "force-reload"
            #       option to the "reload" entry above. If not, "force-reload" is
            #       just the same as "restart".
            #
            echo -n "Restarting $DESC: $NAME"
            d_stop
            sleep 1
            d_start
            echo "."
            ;;
      *)
            # echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
            echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
            exit 1
            ;;
    esac
    
    exit 0
    

    And here's the /etc/default/mediatomb text:
    # Defaults for MediaTomb initscript
    # sourced by /etc/init.d/mediatomb
    # installed at /etc/default/mediatomb by the maintainer scripts
    
    #
    # This is a POSIX shell fragment
    #
    
    # set this to anything else than "yes" if you want to start the MediaTomb daemon
    #NO_START="yes"
    NO_START=""
    
    # Additional options that are passed to the Daemon.
    DAEMON_OPTS=""
    
    # The network interface for MediaTomb to bind to and for which the multicast 
    # routing entry should be added; "" if the route shouldn't be added at all
    #INTERFACE=""
    INTERFACE="eth1"
    

    And here's a portion of /var/log/mediatomb showing what happens at startup:
    2008-02-06 21:51:29    INFO: Loading configuration from: /etc/mediatomb/config.xml
    2008-02-06 21:51:29    INFO: Checking configuration...
    2008-02-06 21:51:29    INFO: Config: option not found: /server/servedir using default value: 
    2008-02-06 21:51:29    INFO: Config: option not found: /server/storage/host using default value: localhost
    2008-02-06 21:51:29    INFO: Config: option not found: /server/storage/database using default value: mediatomb
    2008-02-06 21:51:29    INFO: Config: option not found: /server/storage/username using default value: mediatomb
    2008-02-06 21:51:29    INFO: Config: option not found: /server/storage/port using default value: 0
    2008-02-06 21:51:29    INFO: Config: option not found: /server/ui/attribute::poll-when-idle using default value: no
    2008-02-06 21:51:29    INFO: Config: option not found: /server/ui/attribute::poll-interval using default value: 2
    2008-02-06 21:51:29    INFO: Config: option not found: /server/ui/items-per-page/attribute::default using default value: 25
    2008-02-06 21:51:29    INFO: Config: option not found: /import/filesystem-charset using default value: ANSI_X3.4-1968
    2008-02-06 21:51:29    INFO: Setting filesystem import charset to ANSI_X3.4-1968
    2008-02-06 21:51:29    INFO: Config: option not found: /import/metadata-charset using default value: ANSI_X3.4-1968
    2008-02-06 21:51:29    INFO: Setting metadata import charset to ANSI_X3.4-1968
    2008-02-06 21:51:29    INFO: Config: option not found: /import/playlist-charset using default value: ANSI_X3.4-1968
    2008-02-06 21:51:29    INFO: Setting playlist charset to ANSI_X3.4-1968
    2008-02-06 21:51:29    INFO: Config: option not found: /server/pc-directory/attribute::upnp-hide using default value: no
    2008-02-06 21:51:29    INFO: Config: option not found: /server/retries-on-timeout using default value: 0
    2008-02-06 21:51:29    INFO: Config: option not found: /server/interface using default value: 
    2008-02-06 21:51:29    INFO: Config: option not found: /server/ip using default value: 
    2008-02-06 21:51:29    INFO: Config: option not found: /server/bookmark using default value: mediatomb.html
    2008-02-06 21:51:29    INFO: Config: option not found: /server/modelName using default value: MediaTomb
    2008-02-06 21:51:29    INFO: Config: option not found: /server/modelDescription using default value: Free UPnP AV MediaServer, GNU GPL
    2008-02-06 21:51:29    INFO: Config: option not found: /server/modelNumber using default value: 0.10.0
    2008-02-06 21:51:29    INFO: Config: option not found: /server/serialNumber using default value: 1
    2008-02-06 21:51:29    INFO: Config: option not found: /server/manufacturerURL using default value: http://mediatomb.cc/
    2008-02-06 21:51:29    INFO: Config: option not found: /server/presentationURL using default value: 
    2008-02-06 21:51:29    INFO: Config: option not found: /server/presentationURL/attribute::append-to using default value: none
    2008-02-06 21:51:29    INFO: Config: option not found: /server/upnp-string-limit using default value: -1
    2008-02-06 21:51:29    INFO: Config: option not found: /import/scripting/playlist-script/attribute::create-link using default value: yes
    2008-02-06 21:51:29    INFO: Config: option not found: /server/alive using default value: 180
    2008-02-06 21:51:29    INFO: Config: option not found: /import/autoscan using default value: 
    2008-02-06 21:51:29    INFO: Config: option not found: /import/library-options/libexif/auxdata using default value: 
    2008-02-06 21:51:29    INFO: Config: option not found: /import/magic-file using default value: 
    2008-02-06 21:51:29    INFO: Configuration check succeeded.
    2008-02-06 21:51:29   ERROR: Could not determine interface address
    2008-02-06 21:51:29   ERROR: Could not find interface: eth1
    

    Also, just so you don't think I'm using the wrong interface, ifconfig:
    eth0      Link encap:Ethernet  HWaddr 00:01:29:D1:92:A9  
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
              Interrupt:16 Base address:0xe000 
    
    eth1      Link encap:Ethernet  HWaddr 00:01:29:D1:91:55  
              inet addr:192.168.0.186  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::201:29ff:fed1:9155/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:5020421 errors:0 dropped:0 overruns:0 frame:0
              TX packets:4621539 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:520555782 (496.4 MB)  TX bytes:1097363263 (1.0 GB)
              Interrupt:20 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
    
  • beatzbeatz i am a hamburger Member
    edited February 2008
    Hmm, i can't see anything wrong in the files. Maybe you are on the right track, by thinking that delaying the start of mediatomb will fix things. You wrote, that you tried to delay the start. How?

    You could check the directories /etc/rc0.d, where the symlink for starting your network should be, and /etc/rc2.d, where i think the mediatomb symlink should be. It looks like S**mediatomb, where ** is a two digit number. The higher the number the later the service gets started in the corresponding runlevel.
  • CycloniteCyclonite Tampa, Florida Icrontian
    edited February 2008
    Heh. I did that. I re-registered the script with a value of 99 to give it as long as possible. That didn't work either.

    "update-rc.d -f mediatomb remove"
    "update-rc.d mediatomb defaults 99"

    At least you're verifying my actions were correct. Sometimes I feel like a dummy with Linux. Haha.
  • beatzbeatz i am a hamburger Member
    edited February 2008
    Cyclonite wrote:
    Sometimes I feel like a dummy with Linux. Haha.

    I know what you mean ;). Like in this case. Why the heck, would an init-script work perfektly when called by hand and won't when called during boot? Sorry, but I am out of ideas on this one.

    But maybe, looking at the error message again, you could add entries in /etc/mediatomb/config.xml for these two errors:

    2008-02-06 21:51:29 INFO: Config: option not found: /server/interface using default value:
    2008-02-06 21:51:29 INFO: Config: option not found: /server/ip using default value:

    Maybe that helps ;)
  • CycloniteCyclonite Tampa, Florida Icrontian
    edited February 2008
    I'll see if I can add the interface info to the config.xml. It won't let you specify an interface and IP at the same time. I've already tried IP by itself. :)
  • CycloniteCyclonite Tampa, Florida Icrontian
    edited February 2008
    I got it! It was a little weird that it would say it couldn't find the interface when I'm able to use it for everything else. So, I thought maybe it's just not finding the name. I found out about udev and saw the interfaces getting named in the 70-persistent-net.rules file.

    I started researching udev - networking specifically - and stumbled across another location that is used for naming the interfaces: /etc/network/interfaces. Heh. How obvious is that one?

    Anyway, it turns out that file only had a listing for lo. I added eth0 and eth1, so now it looks like:
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet dhcp
    
    auto eth1
    iface eth1 inet dhcp
    

    After rebooting, the server comes up just fine.

    //Edit: And as a side not, this is the first result when Googling "mediatomb init." Heh.
  • beatzbeatz i am a hamburger Member
    edited February 2008
    Good job! :respect:

    Never would have thought about that one, since the devices were shown by ifconfig, so i just figured, they were configured right in /etc/network/interfaces. I guess, since ubuntu uses NetworkManager for configuring network devices, these settings are no longer made during install.

    Maybe you should write a mail to the developers, so they could put that into their docs or find a fix for that problem.

    Happy streaming ... :rockon:
  • CycloniteCyclonite Tampa, Florida Icrontian
    edited February 2008
    That's a good idea. I may point them to this thread or something. Thanks for your help, beatz!
  • edited November 2008
    I just want to let anyone who may be trying to get this working know, that the instructions here do work (for me, at least), however, you may have to do BOTH of the things the OP tried... namely set up your network interfaces, AND set the run-level for the daemon to 99 so that it is started up after the network interfaces are set up.

    sudo update-rc.d -f mediatomb remove
    sudo update-rc.d mediatomb defaults 99
    sudo gedit /etc/network/interfaces
Sign In or Register to comment.