Saturday, June 18, 2011

Those Annoying @eaDir Files (Synology DS210j NAS)

If you've installed MyMedia Server to your Synology NAS, the first thing you'll likely notice is that there are folders called "@eaDir" everywhere on your system.  This is a "hidden" folder where the server stores thumbnail files associated with iTunes support.  Since we are not using iTunes, we do not need these folders!

To stop the folders from being created:
cd /usr/syno/etc.defaults/rc.d stop stop stop stop
chmod 000

To re-enable the folders being created:
cd /usr/syno/etc.defaults/rc.d
chmod 655 start start start start

To delete *all* @eaDir folders on your system:
CAUTION:  This will delete files without confirmation, so be sure you have it right!!
cd /volume1/music (or wherever your doc root is)
find . -name @eaDir -print | while read n ; echo $n ; rm -rf "$n" ; done

If you are copying files to the NAS from an Mac then sometimes @eaDir folders will reappear.  When this happens, just re-run the above delete script to get rid of them.

MyMedia Automatic Startup on Synology NAS

At this point, I assume you've followed my previous instructions and now have a working copy of MyMedia on your NAS, and you can connect to it and listen to audio from your Roku box.  Currently, though, you have to restart the server every time you power-cycle the NAS.  I have my NAS turn off nightly to save power (and be more quiet) so this obviously doesn't work well for me.

So, the next step is to add a script to the Synology's startup sequence to automatically bring the server up whenever the NAS starts.

1) First step is to create a startup script for our service.  The script should be able to start and stop the server.  Starting the server is easy -- we did that in our last article.  Stopping it, though, requires that we remember the process id (PID) of the server when we start it, so we can then kill that process.  Here's my script, which I called "rc.mymedia".  You can start a new file ("vi rc.mymedia") and copy/paste it into the editor.   I just keep the file in the home directory of the root user.

mymediadir=`dirname $mymedia`

case $1 in
        if [ -e $pidfile ] ; then
            echo "MyMedia server already running. PID=`cat $pidfile`"
        echo "Starting MyMedia server..."
        cd $mymediadir
        $python $mymedia >>$log 2>&1 &
        echo $pid > $pidfile
        cd $c

        if [ -e $pidfile ] ; then
            echo "Stopping MyMedia server..."
            kill `cat $pidfile`
            rm $pidfile
            echo "MyMedia server is not running.  No PID file."
        $0 stop
        sleep 1
        $0 start

2) We will make this an executable script
chmod a+x rc.mymedia

3) You can now start/stop/restart the server with this script
./rc.mymedia start
./rc.mymedia stop
./rc.mymedia restart

4) Next we'll add this script to our local startup sequence.  To do this, edit the file "/etc/rc.local" and add the following lines.  Be sure to use the correct path to your file from above.
# MyMedia Server
[ -x /root/rc.mymedia ] && /root/rc.mymedia start

5) And we're done!  Best to power-cycle your NAS now and see if the server does indeed startup automatically.  If there are issues, here are some things to check:
  • the server debug log at /opt/local/opt/mymedia/server/my_media_log.txt
  • the server error log at /var/log/mymedia.log
  • the PID file at /var/run/
  • the process list, with "ps | grep mymedia"

Installing MyMedia on Synology NAS

One of the main reasons for buying the combination of a Roku DVP and Synology NAS was to stream music from the mp3's on my NAS to my living room, where the Roku is located.  There are a few options, but MyMedia is the only completely open-source and free one, so I decided to give that a try.

Installation of the MyMedia app onto your Roku is well documented elsewhere.  This article will focus on installing the MyMedia server application onto a Synology NAS.  I have a DS210j, but the steps should be the same or similar for other models.

Note:  This requires nominal comfort with the command line.

Here is what I did:
1) Bootstrap your device, and install the IPKG Package Management System.  You can follow my previous instructions on this.

2) After installation, make sure you "ipkg update" and "ipkg upgrade" as directed in the instructions

3) Next we install Python-2.6.  This will download and install all necessary files and may take a bit of time
ipkg python2.6

4) Next up is the Python Imaging Library (PIL)
ipkg install py26-pil

5) Find the URL of the tarball of the MyMedia release you wish to use.  Documentation is a bit sparse on the difference between releases, but in general you should use the latest one.  At time of writing, the latest version was "AngyAvacado" from March 19, 2010.  You want the TGZ version of the archive.

6) Pick an install folder (I use "/opt/local/opt") and fetch/expand the server tarball there
cd /opt/local/opt
wget http://full-url-to-the-version-of-the-server-you-want.tgz
tar zxf name-of-the-file-you-downloaded.tgz
rm name-of-the-file-you-downloaded.tgz

6) I created a symlink to the server folder so I wouldn't have to change any scripts that reference it later
ln -s folder-created-by-tar-command mymedia

7) Start the server, and see if you can connect to it from your Roku MyMedia channel
/opt/bin/python26 /opt/local/opt/mymedia/server/

8) If it is not working, you can check for errors in the log
more /opt/local/opt/mymedia/server/my_media_log.txt

If you see this error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 8: ordinal not in range(128) it means you have non-ASCII characters (accents or what-not) in some of you folders and/or filenames.  Unfortunately, you'll have to rename your folders/files as there seems to be a bug in the Python libraries themselves.

UPDATE:  User "renojim" from the Roku Forum suggests this fix for the character issue. I'll try it soon and report back.
"One thing, try setting $LANG to en_US.UTF-8 before starting the server. The only platform I haven't been able to get accented characters in file names to work is Ubuntu 10.04 and I'm still looking into the problem."

UPDATE:  If you get a error from wget complaining of bad certificates, try adding the "--no-check-certificate" option, which will ignore SSL certificate issues. 

If everything is working, check my next article on how to have your server start automatically on NAS power-up.