So after recently rebuilding one of the servers in my dogghouse, I realized that I hadn’t installed a uPNP/DLNA AV media server. Previously I had been using Fuppes, but the lack of active development and some other quirks made me re-think what I wanted to use. So, after comparing available packages, I decided to give the PS3 media server a try. I specifically wanted something that could run without a GUI on a headless machine as a service/daemon if necessary, that would support an XBox 360 and various Android devices.

Installation was fairly easy, however the documentation to make it work how I wanted on an RPM based distro was conflicting, spread across multiple sites, and somewhat lacking…

First, we need to add the rpmforge repo, in order to install the prerequesites with yum. Instructions for installing RPMForge can be found at the CentOS RPMForge Howto, but it basically consists of the following:

rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -i http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

Next, we need to install some prerequisite packages:

yum install gcc mplayer ffmpeg mencoder java-1.7.0-openjdk ImageMagick

If you wish to stream web content, you will also want to install vlc:

yum install vlc

If you are having problems installing vlc, because of version conflicts with libupnp, add the line exclude=libupnp to your /etc/yum.repos.d/epel.repo, in the main [epel] section

We will also want to install libzen and libmediainfo for some additional features. You can skip this step if you like, but not all the features will work!

You can get RPM packages for libzen and libmediainfo from the MediaInfo Download Page, just select the appropriate distro and architecture, download the package, then install like this:

wget http://mediaarea.net/download/binary/libzen0/0.4.29/libzen0-0.4.29-1.x86_64.CentOS_6.rpm
rpm -Uvh libzen0-0.4.29-1.x86_64.CentOS_6.rpm
wget http://mediaarea.net/download/binary/libmediainfo0/0.7.64/libmediainfo0-0.7.64-1.x86_64.CentOS_6.rpm
rpm -Uvh libmediainfo0-0.7.64-1.x86_64.CentOS_6.rpm

Finally, we are ready to install ps3mediaserver! Go grab the latest ps3mediaserver package from the ps3mediaserver download page, and extract it somewhere. I like to put it in my /usr/local/share directory so that I can run it as a service in the background or as a non-privileged user.

Next, we will follow Geoff Hodder’s advice and create a symlink from /usr/local/share/pms to the current version of pms, which we can change in the future when upgrading, making the upgrade process easier!

ln -s /usr/local/share/pms-1.90.0 /usr/local/share/pms

Double check the ownership here on the pms-1.90.0 folder. I have mine owned as root:root. The default permissions should be correct. Below are what my folder permissions look like.

lrwxrwxrwx   1 root root   27 Nov 19 21:07 pms -> /usr/local/share/pms-1.90.0
drwx------   5 root root 4.0K Jan 29 07:48 pms-1.90.0

Now go to the directory you just created with the ln command above, (/usr/local/share/pms/ in my case), and edit the file PMS.conf, changing the following settings:

minimized = true
network_interface = br0
folders = /data/movies,/data/music,/data/pics

Optionally, edit the following settings to enable chapters on .mkv files, and disable forced subtitles:

chapter_support = true
mencoder_disablesubs = true

If you are upgrading from a previous version of ps3mediaserver, don’t just copy your old config file. Variable names are often changed, new variables are added, and old ones may be removed. Double check your settings and apply them to the new file!

Obviously you will want to change the folders and network_interface settings to match your setup. The defaults for the rest of the settings should be fine, but take a look through the other settings if you wish.

One additional change was made to the /usr/local/share/pms/renderers/XBOX360.conf file to allow avi streaming to the XBox 360. Find the StreamExtensions= line and avi to the end, so it will look like this:

StreamExtensions=wma,asf,avi

Phew… We’re almost there!

One of the things I specifically wanted was to be able to run this as a service on boot. I also wanted to specify my config file, instead of having it use one from my home folder. In order to do this we are going to edit the /usr/local/share/pms/PMS.sh file. Comment out the DIRNAME=`dirname $CMD` line and add a line like DIRNAME="/usr/local/share/pms/" right below it. Here is what the first few lines of my PMS.sh file look like:

#!/bin/sh

CMD=`readlink -f $0`
#DIRNAME=`dirname $CMD`
DIRNAME="/usr/local/share/pms/"

One more thing that I wanted was the ability to simply run a command from anywhere, as any user, and start the service. I just created a symbolic link in the /usr/local/bin to the PMS.sh script like so:

ln -s /usr/local/share/pms/PMS.sh /usr/local/bin/pms

We must now allow TCP traffic on port 5001 and UDP traffic on port 1900 through our firewall, along with multicast IGMP traffic, to actually let this thing work! Open the appropriate ports with some lines like this in your /etc/sysconfig/iptables file:

-A INPUT -s 10.0.0.0/24 -i br0 -p tcp -m tcp --dport 5001 -j ACCEPT
-A INPUT -s 10.0.0.0/24 -i br0 -p udp -m udp --dport 1900 -j ACCEPT
-A INPUT -d 224.0.0.0/4 -i br0 -p igmp -j ACCEPT

You will also need to set the default multicast address route. This can be set in the /etc/sysconfig/network-scripts/route-br0 file, looking like this:

# /etc/sysconfig/network-scripts/route-br0
224.0.0.0/4 dev br0

Make sure to change the source address mask to match your local network addresses, and the interface to match your local network interface. If you have IPv6 running, you should also open those same ports in your /etc/sysconfig/ip6tables firewall:

-A INPUT -p tcp -m tcp -s 2001:1234:5678:abcd::/64 -i br0 -j ACCEPT --dport 5001
-A INPUT -p udp -m udp -s 2001:1234:5678:abcd::/64 -i br0 -j ACCEPT --dport 1900

PLEASE NOTE!!! If you have IPv6 running, you will want to remove the -Djava.net.preferIPv4Stack=true parameter from the last line of the PMS.sh file. More details below…

Again, make sure that your source address mask and interface match your network configuration, and don’t forget to restart your firewalls to apply the new rules!

Now, before we go any further, we can attempt to run the server and make sure that everything is actually working correctly. Just type pms from a command prompt and watch it go!

If everything is working correctly, you will either have the GUI window pop up, or get a message like this:

GUI environment not available
Switching to console mode

or you may get a bunch of debug messages fly by. If there are any errors, double check everything before moving on.

If you are in the console mode, press crtl-c to stop the ps3mediaserver.

Finally, the last thing I want to do is set this thing to run as a service/daemon in the background and start on boot. In order to do this we need a startup script!

Create the /etc/init.d/ps3mediaserver file and put the following in it:

#!/bin/sh
#
# chkconfig: - 91 50
# description: Starts and stops the ps3mediaserver
# version: 0.8
# pidfile: /usr/local/share/pms/ps3mediaserver.pid
# config:  /usr/local/share/pms/PMS.conf

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 1
fi

# Avoid using root's TMPDIR
unset TMPDIR

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1

PROG_NAME='ps3mediaserver'
PROG_ROOT='/usr/local/share/pms'
PROG_JAR='pms.jar'
PROG_EXEC='PMS.sh'

RETVAL=0

start() {
        KIND="$PROG_NAME"
        echo -n $"Starting $KIND services: "
        cd $PROG_ROOT
        daemon $PROG_ROOT/$PROG_EXEC
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && echo `ps axo pid,args | grep $PROG_JAR | grep -v grep | awk {'print $1'}` > $PROG_ROOT/$PROG_NAME.pid || \
           RETVAL=1
           ps axo pid,args | grep $PROG_JAR | grep -v grep | awk {'print $1'} > $PROG_ROOT/$PROG_NAME.pid
        return $RETVAL
}

stop() {
        KIND="$PROG_NAME"
        echo -n $"Shutting down $KIND services: "
        killproc -p $PROG_ROOT/$PROG_NAME.pid
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f $PROG_ROOT/$PROG_NAME.pid
        return $RETVAL
}

restart() {
        stop
        start
}

rhstatus() {
        status -p $PROG_ROOT/$PROG_NAME.pid $PROG_NAME
        return $?
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  status)
        rhstatus
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 2
esac
exit $?

One of the last things we need to do is make a small change to the last line of our PMS.sh script, to allow it to run in the background, and log to a file. The last line should look like this (note the difference between IPv4 and IPv6 networks!):
IPv4:

exec "$JAVA" $JAVA_OPTS -Xmx768M -Xss1024k -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -Djna.nosys=true -classpath "$PMS_JARS" net.pms.PMS "$@" >> /var/log/ps3mediaserver.log 2>> /var/log/ps3mediaserver.log &

IPv6:

exec "$JAVA" $JAVA_OPTS -Xmx768M -Xss1024k -Dfile.encoding=UTF-8 -Djna.nosys=true -classpath "$PMS_JARS" net.pms.PMS "$@" >> /var/log/ps3mediaserver.log 2>> /var/log/ps3mediaserver.log &


I have not been able to get the IPv6 configuration for PS3 Media Server to work reliably on all my devices… If you have any suggestions please let me know!

Finally, install the startup script and set it to run on boot!

cd /etc/init.d
chmod +x ps3mediaserver
chkconfig --add ps3mediaserver
chkconfig --level 345 ps3mediaserver on

Now, we can start the ps3mediaserver and be done!

service ps3mediaserver start
Starting ps3mediaserver services:                          [  OK  ]

Now that we are done, go ahead and get yourself a dogg treat!

Thanks to Geoff Hodder for some good tips left in the comments below. Go check out his page at PHReeK.oRG

Also, thanks to the following webpages for giving me some of the information necessary to get this thing working:
http://www.ps3mediaserver.org/forum/viewtopic.php?f=3&t=4374
https://help.ubuntu.com/community/Ps3MediaServer
http://otmanix.de/english/2009/05/17/java-ps3-media-server-for-dummies-chapter-3-installation-and-basic-configuration/