Railo on Raspberry Pi

21 Jun 2013
Raspberry Pi Coldfusion


Please Note:
This post appears to be over 6 months old.

Why install Railo on the Raspberry Pi? I cannot tell you why, maybe I was just bored, or maybe I just wanted to see if it was possible. However, one thing I have learnt is that Railo can just about run on anything!

RaspiModelB

The Pi

For those who don’t know about the Raspberry Pi, it’s a small (credit-card sized measuring 85.60mm x 53.98mm x 17mm), inexpensive computer with 512MB of RAM, a 700MHz CPU and a GPU capable of 1080p output over HDMI . Connectivity is provided via 2 USB 2.0 ports, and a RJ45 10/100 Ethernet port. The GPU is capable of BluRay quality playback, using H.264 at 40MBits/s.

The Raspberry Foundation is a charity founded in 2009. The premise is to sell an inexpensive small computer that the younger generation can learn to program with. It’s a fantastic idea and with the year-on-year decline in the numbers applying to read Computer Science, Eben Upton and his colleagues at the University of Cambridge’s Computer Laboratory are hoping this device will help carry the next generation of uber geeks.

For myself, and I’m sure fellow nostalgic techheads it’s also a cool way to bring back the memories of the Spectrum ZX and Commodore 64 days. I know there are better, smaller, computers on the market today like Android’s MK802 for example, but it seems the Pi is capturing people imaginations, young and old! I have read about some very interesting projects, peripherals, media centres, mini robots and even a Pi powered space balloon!

So what are my goals? Well, long term I want to create a battery powered NFC reader.  Yep that’s my main goal, however for this blog post and to get my toes wet, I’m writing about how I got Railo Server running on the Pi. I think it’s pretty cool and leads me on to a very interesting conclusion you can read at the end of this post.

Ordering My Pi

RaspiModelB

First let me tell you where and how I got my Pi. I order my Raspberry PI from Farnell/Element14 for just £30 (it sells for around $35 US Dollars). The device is powered by a standard micro USB port. This ought to be enough current to power a USB mouse and keyboard. However, using networking and high-current USB peripherals such as a WIFI dongle requires a supply which can source 700mA plus. To be on the safe side I decided to order a power supply that can be plugged into the mains (recommended range of 4.75v to 5.25v).

Next, I needed an SD card for the operating system. I found a cheap 8GB class 10 card off eBay for £6, including postage.  I also ordered a micro WI-FI dongle too. The Pi has a standard Ethernet port built in, but using that would be no fun! It had to be Wi-Fi or no FI! Wow, sorry that was bad, I’m ashamed, honest!

RaspiModelB

I purchased a clear plastic case for the device on Amazon UK. Not just for the ascetics, the case helps with the durability of the unit. I found the SD card when inserted into the device protrudes. I was concerned this would result in me snapping the unit (I’m like a big handed giant). The case helps with this flimsiness issue and gave it a more robust feel.

The day the Pi arrived on my desk I was lucky enough to receive the new 512MB. The new version had come out just days before I ordered. All future Model B Raspberries will have the upgraded memory at no extra cost.

Installing the OS

My first undertaking was to download an OS image to the SD card. There are a wide range of images available for the Pi. I decided to use the Debian based Raspbian “wheezy” distribution from raspberrypi.org/downloads . It has most of the things I needed preconfigured and was designed to work specifically with the Pi. Perfect for a novice like me!

I burnt the image onto the SD from my Mac. It was simple to burn the image to the SD card. I just insert the SD card; open up a terminal session and burnt the downloaded Raspbian image.

df -h

The command for copying the .img won’t work while the device is mounted, I used the following command first. My card was on disk1…

diskutil unmountDisk /dev/disk1

Finally, I can copy the .img file to the SD card using the ‘dd‘ command *important r before disk1:

sudo dd bs=1m if=/Users/glyn/Desktop/wheezy-raspbian.img of=/dev/rdisk1
  

Waiting for the image to copy did take some time to complete, around 3 minutes, but once done I ejected the card and could not wait to start the Pi.

For the sake of transparency I tried to mount the image using Windows 7 too. I found this to be more involved than on the Mac. For a start, I had to download a utility called Win32DiskImager to mount the card and format it correctly. It took a bit of trial and error, issues with partitions etc, but I got there in the end.

When the image was finally written to the card it created three different partitions. A boot partition, a Linux system partition and a swap file partition. They were sized to fit a 2GB SD card and the additional space on the 8GB (around 6GB) was unallocated and at that point meaning it was unusable! I allocated the spare space to use the full capacity of the SD card. This process is not really involved and just requires you to create a new partition and move a few things around. There are lots of instructions on the internet on how to do this so I’m not going to cover it this time.

Boot up

Once the OS image was created and the card inserted it was time for its first boot. The default username for the Debian image is pi and the password is raspberry. You can load the LXDE desktop environment by entering startx. However, this is not something I have yet done and my Pi after configuration won’t be using a screen, in fact it won’t be using any input peripherals.

Prepare for .ssh no screen

For my projects I would like to plug in power and let it do its thing. I don’t need nor want a screen. SSH is a secure method of logging onto a remote computer, but you already known that right? I often terminal into instances running Linux from a Windows machine using Putty and my Mac using Terminal.  The Pi was not going to be the exception to this rule so next I setup .ssh.

Firstly, I installed the SSH service. This was done by this command:

sudo apt-get install ssh 

easy, right? I then started the daemon (Unix name for a service) with this command from the terminal:

sudo /etc/init.d/ssh start

This init.d is used to start other daemons. For example if you have Apache, MySQL, Samba etc. You can also stop the service with stop or restart it with restart.

To set it up so the ssh server starts every time the Pi boots up, I run this command (just once):

sudo update-rc.d ssh defaults

Just to check if this worked I then restarted the Pi:

sudo reboot –h now

It’s also worth noticing that the Pi can be restarted by replacing –h with –r… which makes sense.

I've manage to corrupt my SD card a few times now through poweroffs before it had halted. So, a word of warning to anyone experimenting with the Pi, only power down once you have fully shut down your Pi!

One the Pi was on my network I found out its internal IP by typing the following:

/sbin/ifconfig

This gave me the internal IP address I needed to Putty into the machine. It’s also very easy to give your Pi a static IP if you wanted to access it externally!

WIFI

As is the case with Linux in general, wireless can be a bit patchy and the the Raspberry Pi is no exception. It took me awhile to get the Pi configured with the DIGITAZZ Wifi 802.11n WiFi dongle I purchased from eBay. The adaptor uses the Ralink RT 5370 chipset. I found the firmware packages RT2800usb online and installed it.

To see which networks are available, you just type:

iwlist wlan0 scan

This should give you a list of wireless networks around you. Lastly, I had to configure the adaptor

sudo nano /etc/wpa.conf
network={
  ssid="YOUR-SSID"
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk="WPA-PASSWORD"
  }
  
  

And reference this in /etc/network/interfaces:

$ sudo nano /etc/network/interfaces
  
  # Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
  # /usr/share/doc/ifupdown/examples for more information.
  auto lo
  iface lo inet loopback
  iface eth0 inet dhcp
  auto wlan0
  iface wlan0 inet dhcp
  wpa-conf /etc/wpa.conf
  

I restarted the unit as shown above and my binky light on the Wifi adaptor was flashing, that’s the real technical term honest! Ifconfig showed me that I has both sent and received packets on wan0. I disconnected the Ethernet port and one more wire was gone, yippee!

Installing Railo

Installing Tomcat 7 was easy, but first I needed to download and install JAVA.

sudo apt-get install sun-java6-jdk
  

Then Tomcat 7:

wget http://mirror.ox.ac.uk/sites/rsync.apache.org/tomcat/tomcat-7/v7.0.32/bin/apache-tomcat-7.0.32.tar.gz
tar xzf apache-tomcat-7.0.28.tar.gz
  
  mv apache-tomcat-7.0.28 tomcat7
  
Before I started Tomcat, I next added the correct user that has permissions to deploy applications found in tomcat-users.xml:
<user username="system" password="raspberry" roles="manager-gui"/>

To finish the Tomcat install I just restarted. If you’re familiar with Tomcat you will already know this is done by running startup.sh script in the tomcat ‘bin’ folder.

It’s a shame it’s possible to use the Railo installer on the Pi. The Railo installer is designed to work with Intel based chipsets (from the best of my knowledge). This meant a manual install.

To install Railo manually, I needed to get the Railo custom version and copy all of the files into the Tomcat lib directory I just created.

wget http://www.getrailo.org/down.cfm?item=/railo/remote/download/3.3.4.003/custom/all/railo-3.3.4.003-jars.tar.gz
  

I have always found a strange issue with using wget on the Railo download links. For some reason when the file is downloaded is looks like this:

down.cfm?item=%2Frailo%2Fremote%2Fdownload%2F3.3.4.003%2Fcustom%2Fall%2Frailo-3.3.4.003-jars.tar.gz
  
  

I always rename the file so it makes more sense. Next, I just unzipped the file

tar zxvf railo-3.3.4.003-jars.tar.gz
  
  

Then move to the tomcat directory:

sudo mv railo-3.3.4.003-jars /* / apache-tomcat-7.0.32 /lib
  

Open up the web config file.

  sudo nano tomcat7/conf/web.xml
  

Append the following inside the element:

<servlet>
  <servlet-name>CFMLServlet</servlet-name>
  <servlet-class>railo.loader.servlet.CFMLServlet</servlet-class>
     <init-param>
        <param-name>configuration</param-name>
        <param-value>{web-root-directory}/WEB-INF/railo/</param-value>
        <description>Configuraton directory</description>
     </init-param>
     <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
     <servlet-name>CFMLServlet</servlet-name>
     <url-pattern>*.cfm</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
     <servlet-name>CFMLServlet</servlet-name>
     <url-pattern>*.cfml</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
     <servlet-name>CFMLServlet</servlet-name>
     <url-pattern>*.cfc</url-pattern>
  </servlet-mapping>
  

Inside the element insert the following:

index.cfm
  index.cfml
  
  

RaspiModelB

Well that was that! Railo was installed and working! I’m not sure why I was so surprised, Railo is a very versatile engine. It actually works well on the Pi, it takes a little time to load first time, but after it’s around the same speed as JSP file. That’s not a real benchmark, but still you get the idea.  I may have a use for Railo on the Pi with my RFID reader, interesting…

That's all Folks!

Thanks for reading. Let's keep in Touch:
Follow me on GitHub or Twitter @glynjackson


Glyn Jackson is a Python Nerd, consultant and developer.


Find out more