Mobile Media Server with a Raspberry Pi

November 6, 2013 3 comments

Update: 8.Nov.2013 – Tweaked WiFi config to improve network performance.

This thanksgiving we are planning to drive, for once, to our destination in Southern California. In anticipation of the kids getting bored on the long drive, I started to think about a way to have more videos available than their iPods/iPads can hold, to keep them busy.

The idea I came up with was to see if I could configure a Raspberry Pi as a media server. You can hardly beat the form factor, and the simple power requirements, perfect for the car. I figured it would have to do a few things

  1. Act as a WiFi Access Point. The iDevices would be configured to connect to this.
  2. Serve as a simple DNS server for this isolated LAN.
  3. Serve media files in some way that the iDevices could understand.
  4. Handle the load of a few clients accessing it

After about a day’s work, I’m happy to report that I believe I have been successful. At least my initial configuration and testing so far is looking very promising. Here’s what I have done:

Configuring the WiFi Access Point
I found a great tutorial from Adafruit for Setting up the Raspberry Pi as an Access Point. Followed the instructions pretty much verbatim, and it ok, but in later testing I noticed wireless performance was pretty slow. I found the article Raspberry Pi with RT5370 Wireless Adapter which described a similar problem but with a different adapter.

Still his solution was simple so I gave it a shot and it worked. What I ended up doing is changing /etc/network/interfaces to add the directive wireless-power off, so the section now looks like

iface wlan0 inet static
  wireless-power off

I was worried that once I disconnected the ethernet side of the Pi, things would go haywire, like maybe the iDevice would no longer want to connect to the Access Point since it could no longer fully access the Internet. But that doesn’t appear to be a problem so far.

Setting up the DNS server
I wasn’t entirely sure I would need this, but thought I’d do it just in case. Found this tutorial for Setting up a simple intranet DNS Server on Linux, using dnsmasq.

I did a couple things different than the how-to though. First, I installed the full dnsmasq package (not just dnsmasq-base).

I also used a different location for the config file, to match the newer pattern for where to store dnsmasq config files, I created the file called/etc/dnsmasq.d/intranet.conf

In there I put




Note that the server= directive should probably be removed since in disconnected mode, there is really no upstream server to consult.

Finally, I then went back and tweaked /etc/dhcp/dhcpd.conf, to point the domain-name-servers option to

Installing a Media Server
My first hope was to just use Samba to provide a CIFS share to the iDevices. I have a used an app called File Explorer on the iPad which works fine talking to beefier hardware, but the Raspberry Pi struggled to serve media very well, so I looked for other solutions.

In my search I found several DNLA clients available for iOS, so I thought I’d give that a shot, so far it has worked well.

I followed the tutorial Mini DNLA on the Raspberry Pi. Pretty simple and straight forward.

I noticed in the minidlna.log it kept complaining that there were not enough max_user_watches, so I followed the instructions to increase the limit.

DLNA Video Players
And finally, I’ve tried out several DLNA-enabled video players, here’s two good ones I’ve found so far

  • MoliPlayer & MoliPlayer HD – Easy to use player, have a few optional in-app purchases to enhance viewing.
  • XBMC for iOS – If you happen to have a jail broken device, this works well and is free.
Categories: Uncategorized

Of Tomcat, OutOfMemory Errors & Continuous Development

March 14, 2013 Leave a comment

So you are working in your favorite IDE on some sort of web application or web service, and you are continuously deploying to Tomcat but ocassionally the deployment fails, you see the CPU of the JVM process spike to 100% and you see something like java.lang.OutOfMemoryError: PermGen space show you in your catalina.out file.

The root cause is arguably either a memory leak in Tomcat or something that your application is not cleaning up when its being undeployed/shut down.

But never mind that, you just are annoyed by having to find the process ID of the Tomcat JVM and kill it so you can restart Tomcat.

Instead of doing all that by hand, you can have the JVM kill itself when it encounters this condition, with the use of the “-XX:OnOutOfMemoryError” JVM option. It is as simple as starting up the JVM with the option

-XX:OnOutOfMemoryError="kill -9 %p"

Now, I use NetBeans, and it’s actually not that trivial to try to specify this option correctly in the NetBeans tomcat config, so I punted to just tweaking the script, here’s what I did.

First, I made a backup of


Next, I added the following lines just after the initial comment block in the file.

OOM_OPTS="-XX:OnOutOfMemoryError=kill -9 %p"
export OOM_OPTS

Finally, I found every location where the JVM was being invoked and added “$OOM_OPTS” to the argument list. Its actually pretty easy to do with a sed command

sed -e 's/\($JAVA_OPTS $CATALINA_OPTS\)/\1 "$OOM_OPTS"/g'

And voila. Next time you restart Tomcat, when it encounters an OutOfMemory condition it will kill itself automatically.

Categories: Computing Tags: , ,

Quickie to show IP Addresses on console login

September 25, 2012 Leave a comment

Here’s a simple script to put into /etc/rc3.d/ to add the IP addresses to the /etc/issue file so that they appear on the console login screen. Handy for environments like Virtual Box or VMWare, to display the IP addresses that were configured via DHCP so I can SSH directly into the system.

# /etc/rc3.d/S99issue

cp /etc/issue /tmp/issue-$$
head -3 /tmp/issue-$$ > /etc/issue
ifconfig | awk '/^[a-z]/{ i=$1 } /inet addr/{print i,"\t",$1,$2}' >> /etc/issue
echo >> /etc/issue
rm -f /tmp/issue-$$
Categories: Computing Tags: , ,

Adding custom Class-Path entries to a Netbeans Java Application Project

August 31, 2012 Leave a comment

I want to jot this down before I forget. I was working in a Netbeans Java Application project, but I wanted to augment the Class-Path of the MANIFEST.MF in the Jar file to include an additional location.

If you’ve looked at a project, you’ll notice that Netbeans does create a MANIFEST.MF itself, but if you attempt to add a Class-Path property by hand, it will get bundled verbatim, so any additional libraries that Netbeans would have added for you don’t get added.

I ended up with this solution. I added this to the build.xml file

<target name="-pre-jar">
    <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
    <pathconvert property="">
        <path path="${run.classpath}"/>
        <map from="${build.classes.dir.resolved}" to=""/>
    <pathconvert pathsep=" " property="jar.classpath">
        <path path="${}"/>
            <globmapper from="*" to="lib/*"/>
    <manifest file="MANIFEST.MF">
        <attribute name="Class-Path" value="${jar.classpath} lib/"/>

Most of the meat of the target is taken from nbproject/build-impl.xml, the only thing I have really done is add the desired paths to the “Class-Path” line, in this case I just added “lib/” in there.

Categories: Computing Tags: ,

Compiling Java-Readline with GNU readline for OSX

February 8, 2012 4 comments

I had previously wrote some instructions for compiling the libreadline-java on OSX with the built-in readline libary on OS X (for use with Henplus). Its time to revisit that, cause it had some issues.

  • OS X Lion, and maybe other versions, doesn’t ship with GNU readline at all. Instead, it ships with a BSD-licensed alternative called libedit, which has a compatibility layer to emulate GNU readline, but has some weird quirks that for those used to GNU readline get annoyed with.
  • libeadline-java I have since found already supports libedit. I didn’t realize that at the time, and so the patches I made do essentially the same thing as if libreadline-java were configured to compile against libedit in the first place.
  • And also, this guy Andre keeps bugging me, I don’t know him, but don’t want to let him down none the less.

The new strategy is this, compile your own GNU readline, then point libreadline-java at it and compile against your new GNU readline library. There’s still some tweaks that need to be done, but there are less and they are more straight forward.

Compiling GNU readline

There’s only one small tweak you have to make to the build scripts to get it to compile correctly, at least for Lion. The latest version of GNU readline, version 6.2, doesn’t have support for compiling against Lion, but thanks to some other sleuthing, the tweak is pretty simple:

In the file support/shobj-conf,

  • Find the line darwin[89]*|darwin10*) and change it to darwin[89]*|darwin10*|darwin11*)

Now, configure, build and install as usual, we’ll target /usr/local as the destination

configure --prefix=/usr/local
make intall

Ok, done with that. I’ve made a readline-6.2-osx-lion.patch for those of you interested.

Tweaking Java-Readline

Ok, now on to compiling libreadline-java with the freshly build libreadline. First off, the list of tweaks you need to make

In the source root, edit Makefile and make the following changes:

  • Below the line # Operating system dependent
    Add JAVA_HOME = `/usr/libexec/java_home`
  • Change the JAVAINCLUDE variable
    to /System/Library/Frameworks/JavaVM.framework/Headers
    (This is needed to find jni.h)
  • Change the JAVANATINC variable to /usr/local/include

Next, edit src/native/Makefile and change the following:

  • Change the  LIBPATH variable to -L/usr/local/lib
  • Change the CFLAGS to -fno-common
  • Change $(CC) -shared (OBJECTS) $(LIBPATH) $($(TG)_LIBS) -o $@ to
    $(CC) -bundle -flat_namespace $(OBJECTS) $(LIBPATH) $($(TG)_LIBS) -o $@

Now, you can run make, and you will end up with and libreadline-java.jar.

Rename to libJavaReadline.dylib, and you are set. You can now go on to use libreadline-java in your target application, like Henplus, as you expect.

I’ve made a libreadline-java-0.8.0-osx-lion.patch script for those who would rather use the patch command rather than doing it by hand.

Categories: Computing Tags: , , ,

These are a few of my favorite apps…

December 10, 2011 Leave a comment

I’m sure everyone’s got ‘em. When you get past the facebook an twitter clients, what are the iOS apps you really find useful? Here’s a bunch of mine. What’s yours?

Air Video – This is a really cool app and accompanying server to let you play your own videos, anywhere. No iCloud necessary! Dup your DVD collection and watch it where ever an whenever you want. I’ve got about 2Mbit outbound bandwidth which is more than enough for nice looking video on any iOS device.

Xfinity TV – for as much as we all hate Comcast, this app fills some glaring voids in their on-screen UI. Search listings easier. Better organization to on-demand offerings and even control your TV from the app.

IM+ Pro, Touch Term, Pocket Cloud – this trio of apps is a pretty good set to have for any system administrator, giving you instant messaging, SSH, VNC and RDP clients.

Wikinvest, Mint – both great tools to manage your investments and personal finances. Tie in pretty well with their respective sites.

Mobile Mouse – another client/server pair. Gives you a virtual keyboard & mouse so you can control your Windows an Mac OS systems.

Reeder – nicely packaged Google Reader enabled feed reader. This replaces Mobile RSS which, up until iOS 5 was my reader of choice.

Push Mail – great app/service to allow you to send Notifications to your phone via email. You can configure different profiles for different messages to display different email fields in the Notifications.

IProxy – happen to still have an unlimited data plan and a developer device? Use iProxy instead of enabling full fledged tethering.

Flipbook – yeah the UI I’d kind of gimmicky and hard-cores will probably get their news elsewhere but it’s a nice read for standing in the grocery line.

Categories: Computing Tags:

MySQL user@localhost and user@%

November 2, 2011 Leave a comment

Its always bugged me that I have to create two user accounts in MySQL, one with a wildcard host (%) and another for localhost.

Finally investigated it enough to understand why. Briefly, three things are going on.

  1. First, MySQL takes a non-wildcard host as precedence when looking for user accounts
  2. The mysql_install_db script create an anonymous user account ”@’localhost’
  3. The anonymous use account takes precedence when the hostname matches.

So the net effect is that when you connect locally, in general MySQL will use the anonymous account to authenticate to, no matter what you specify as a username, if the only account that matches the username also has a wildcard host field.

This is explained in the MySQL reference manual:

It is necessary to have both accounts for monty to be able to connect from anywhere as monty. Without the localhost account, the anonymous-user account for localhost that is created by mysql_install_db would take precedence when monty connects from the local host. As a result, monty would be treated as an anonymous user. The reason for this is that the anonymous-user account has a more specific Host column value than the 'monty'@'%' account and thus comes earlier in the user table sort order.

I’m not quite sure why an anonymous user is created by default, some documentation suggests that on Windows, its used as the ‘root’ account.

Interestingly, although you need both user@localhost and user@%, you don’t also need to grant privileges to both users. It appears to be sufficient to grant privileges to user@% and those privileges will also be used for user@localhost (this was another source of confusion for me.)

If it bugs you so much, there are other options

  • remove the anonynous account(s) entirely. I’ve seen references in a couple of places suggesting this is an okay thing to do
    delete from mysql.user where user = ''
  • rename the anonymous account(s). If deleting them seems a little too drastic
    update mysql.user set user = 'visitor' where user = ''

I’m not sure which option I like, but now I finally understand MySQL authentication better.

Categories: Computing

Get every new post delivered to your Inbox.