How to Install Universal Media Server UMS on Ubuntu in Headless mode

Updated for Ubuntu 14.04
10-19-2015

Universal Media Server is a fork off the very useful PS3 Media Server. And although the PS3MS was a great solution, it did have some shortcomings, especially with certain file formats or file containers. I tried UMS and loved it. It is easy to install and, at least for now, streams and transcodes every media file I have to support playback on any device including the PS3 and the sony SMP-N200 I use on other TVs.

So, working with any Ubuntu 14.04 server, here is my step by step to get UMS installed and working.

First you must have Java 7 JRE installed on the server. OpenJava will not work.

apt-get install software-properties-common
apt-get update
apt-get install openjdk-7-jre openjdk-7-headless

With Java installed, we now need to add some other pre-reqs:

apt-get install mediainfo dcraw vlc-nox mplayer mencoder

I’m going to use the /opt directory for the install. Then we download the latest UMS package from sourceforge. You can check the UMS webpage to find the latest version. As I write this, the latest is 5.2.3. After the download is complete, unpack the file with tar. I create a softlink using /opt/ums so that when we need to upgrade, we can just point the softlink to the new directory while not touching the config files that we will be using in /etc/ later on.

cd /opt
wget http://sourceforge.net/projects/unimediaserver/files/Official%20Releases/Linux/UMS-5.2.3-Java7.tgz
tar -xvzf UMS-5.2.3-Java7.tgz
ln -s /opt/ums-5.2.3 ums
rm UMS-5.2.3-Java7.tgz

Next we need to create the init.d script to auto start the app when the server boots, as well as have better control over the service.
We will create /etc/init.d/ums.

nano /etc/init.d/ums

Copy the following into the new file:

#!/bin/bash
#
### BEGIN INIT INFO
# Provides:          ums
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts UMS program.
# Description:       Java Upnp Media Server dedicated to PS3
### END INIT INFO

#set -x

# Author: Papa Issa DIAKHATE <paissad@gmail.com>
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Universal Media Server"
NAME=ums
UMS_PROFILE=/etc/UMS.conf
DAEMON=/opt/ums/UMS.sh
DAEMON_OPTS="console"
SCRIPTNAME=/etc/init.d/ums
UMS_START=1 # Wether to start or not UMS ver at boot time.
DODTIME=30  # Time to wait for the server to die, in seconds.
            # If this value is set too low you might not
            # let the program to die gracefully and 'restart' will not work

test -x $DAEMON || exit 1

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Include ums defaults if available
if [ -f "/etc/default/$NAME" ] ; then
        . /etc/default/$NAME
fi

# May we run the init.d script ?
[ $UMS_START = 1 ] || exit 1

#--------------------------------------------------------------------------
# Some color codes
txtred=$'\e[0;31m' # Red
txtylw=$'\e[0;33m' # Yellow
txtrst=$'\e[0m'    # Text Reset
#--------------------------------------------------------------------------
warnout(){
    echo >&2 -e ""$txtylw"Warning:$txtrst $1"
}
#--------------------------------------------------------------------------
running(){
    pid=`pgrep -f 'java .*ums.jar.*'`
}
#--------------------------------------------------------------------------
do_start(){
    running && { warnout "$NAME is already running !"; exit 0; }
    echo "Starting $DESC : $NAME"
    UMS_PROFILE="$UMS_PROFILE" start-stop-daemon --start --quiet --background --oknodo \
        --exec $DAEMON -- $DAEMON_OPTS

}
#--------------------------------------------------------------------------
do_stop(){
    running || { warnout "$NAME is NOT running !"; exit 0; }   
    local countdown="$DODTIME"
    echo -e "Stopping $DESC : $NAME \c "
    kill -9 $pid
    while running; do
        if (($countdown >= 0)); then
            sleep 1; echo -n .;
            ((--countdown))
        else
            break;
        fi
    done
    echo
    # If still running, then try to send SIGINT signal
    running && { \
        echo >&2 "Using kill -s SIGINT instead"; \
        echo >&2 "If you see this message again, then you should increase the value of DODTIME in '$0'."; \
        kill -2 $pid; \
    }

    if [ -e "/usr/share/ums/debug.log" ]; then
    count=9
    while [ $count -ge 1 ]
    do
    if [ -e "/usr/share/ums/debug.log.$count" ]; then
        plus=$((count+1))
        mv "/usr/share/ums/debug.log.$count" "/usr/share/ums/debug.log.$plus"
    fi
        count=$((count-1))
    done
    if [ -e "/usr/share/ums/debug.log" ]; then
        mv "/usr/share/ums/debug.log" "/usr/share/ums/debug.log.1"
    fi
    fi

    return 0
}
#--------------------------------------------------------------------------
do_force-stop(){
    running || { warnout "$NAME is NOT running !"; exit 0; }   
    echo "Stopping $DESC : $NAME"
    kill -9 $pid
    if [ -e "/usr/share/ums/debug.log" ]; then
    count=9
    while [ $count -ge 1 ]
    do
    if [ -e "/usr/share/ums/debug.log.$count" ]; then
        plus=$((count+1))
   mv "/usr/share/ums/debug.log.$count" "/usr/share/ums/debug.log.$plus"
    fi
       count=$((count-1))
    done
    if [ -e "/usr/share/ums/debug.log" ]; then
   mv "/usr/share/ums/debug.log" "/usr/share/ums/debug.log.1"
    fi
    fi
}
#--------------------------------------------------------------------------
do_status(){
    echo -n " * $NAME is "
    ( running || { echo "NOT running "; exit 0; } )
    ( running && { echo "running (PID -> $(echo $pid))"; exit 0; } )
}
#--------------------------------------------------------------------------
case "$1" in

    start|stop|force-stop|status)
        do_${1}
        ;;
    restart|reload)
        do_stop
        do_start
        ;;
    force-restart|force-reload)
        do_force-stop
        do_start
        ;;
    *)
        echo "Usage: $SCRIPTNAME {start|stop|force-stop|restart|force-restart|reload|force-reload|status}"
        exit 1
        ;;
esac

Now add execute permissions to the script and add the UMS script to update-rc.d

chmod +x /etc/init.d/ums
update-rc.d ums defaults

A sample conf file that you could use is at /opt/ums/UMS.conf and could be copied into /etc/UMS.conf and edited to fit your needs. It has all the configurable options and is probably more than most will need. You should also copy in the WEB.conf file as well to handle web streams if you use that functionality. (Thanks Wolfgang Hochweller)

cp /opt/ums/UMS.conf /etc/
cp /opt/ums/WEB.conf /etc/

Configuration is done to the /etc/UMS.conf file. At the very least you will want to add the location of the media to share.

folders=/mnt/media/tv, /mnt/media/movies, /mnt/media/music 

Pay attention to the following items, especially for those hosts with multiple NICs.

network_interface=
hostname=
port=
folders=

Now start UMS:yty

service ums start

That’s it, it should be running and advertising itself as UPNP/DLNA on the local network.