PS3 Media Server As A Linux Service

In a previous blog I detailed how I’d managed to get PlayStation 3 Media Server (PMS) up and running on my Lubuntu box, and had it starting automatically.  At this stage there were 2 problems with the setup:

  1. PMS was running as root, which is a self-evidently Bad Thing TM
  2. It was serving every folder from “/” downwards – when all I really wanted was a TV and a Film folder, both mounted under /media

So my goal for today was to complete the following steps to rectify this and have my PMS running on startup, and only showing the correct folders.  My plan was:

  1. Create a user (‘pms’) to be responsible for running the PlayStation 3 Media Server program (reference)
  2. Give the user (minimal) permissions needed to do this (reference 1, reference 2)
  3. Change my startup routine to make sure the PMS started as the right user
  4. Sort out the configuration so only the right folders are shown to the clients

So let’s get started

Setting up the User

sudo useradd pms

This creates a user called ‘pms’ and, since I didn’t specify a group, creates a group with the same name to add them to. I now have a user called pms in a new group called pms.  A quick look at my own user’s groups showed that it was in the following groups: adm, dialout, cdrom, plugdev, lpadmin, admin and sambashare.  (You can check a user’s group memberships using the command groups username).  See the Ubuntu documentation on sudo,

Of those, the only one it seemed pms would need to be a member of is sambashare, as the media my server will stream isn’t actually on a local hard drive but on a NAS drive, mounted to the server as a samba share, so:

sudo usermod -a -G sambashare pms

At this point I tried running the server as the user pms. When I did this I got an exception, complaining that it couldn’t create PMS.conf in /usr/lib/ps3mediaserver.

Ahh… Permissions
I decided to ‘fix’ this by assigning the directory to the pms group and giving the group write permissions, i.e.

sudo chgrp pms /usr/lib/ps3mediaserver
sudo chmod 775 /usr/lib/ps3mediaserver

I logged in as pms and verified that I could start the ps3mediaserver in console mode. It worked, and created a (basically enmpty) PMS.conf file in /usr/lib/ps3mediaserver – though why this didn’t get created when the program was running as root, I don’t know.

I also had a goal of only sharing specific folders rather than everything starting at root, so I edited the file and added a line to do this, escaping any ‘/’ in the path with ‘\’ so: folders = \/media

Start PMS (application) – as a Service – as pms (user)
Last thing to do now was to edit my startup script created yesterday (/etc/init.d/pmsautostart) so that it launched the program as pms instead of root. I added sudo -u pms to my command to start the service as pms, so the whole script now looks like:

#!/bin/bash
nohup sudo -u pms /usr/bin/ps3mediaserver &
exit

And you should be ready to go!

I did notice at this point that the PS3 could only see folders, not files, after it had been working fine previously! After a hunch led me to believe it was because the PMS.conf file created was empty (only had a UUID line, nothing else), I added a line for the folders, but nothing about the encoders. This didn’t help, however after copying my pms.conf file from ~/.config/ps3mediaserver I tried restarting the PS3 and hey presto! I think the PS3 just needed a restart – oops!

Author: nerd.

An experienced IT professional, I used to run a number of small websites and spend a lot of time tinkering with my sites or my PC - back when I had free time.

Leave a Reply

Your email address will not be published. Required fields are marked *