Sunday, 21 June 2015

WildFly on the Raspberry Pi

Recently I got myself a Raspberry Pi model 2B. The main rationale was to have a cheap but full featured platform to do some R&D work on. With a 900MHz quad-core ARM Cortex-A7 CPU and 1GB of RAM it has enough oomph for that.

On the Raspi I want to run a X509 certificate laboratory. With this CertLab I can issue the certificates I need for development and demonstrations. My CA platform of choice is the excellent open-source EJBCA. As it requires a JEE5 compliant application server the hunt was on to find one that would run on my little Pi. According to the EJBCA installation documentation you basically have the choice between JBoss and Glassfish. As I had some experience with the JBoss platform this was the obvious choice.

The Raspbian image on my Pi ships with Oracle Java by default, with version 1.8 of the JDK.

$ java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)

Unfortunately JBoss AS7 does not play nicely with JDK 1.8, forcing me to go one better and try WildFly.

Installing WildFly

The actual installation of WildFly is pretty straightforward. This post contains a detailed guide of the necessary preparation and the install itself

Create system user

The first step of the preparation is creating a system user to run WildFly with. The default scripts all presume they are running under the context of the user wildfly so let’s create that user.

? pi
$ sudo adduser --system --shell /bin/bash --group wildfly

Create directory structure and download the software

I like to use an /opt/default directory to store the default versions of the software I use. If I muck up too badly I can use that plain version to start over. From the /opt/default directory the software is copied to the /opt directory itself. To facilitate upgrading the software to a newer version a symbolic link is used to point to the version of the software you would like to use.

? pi
$ sudo mkdir /opt/default
$ cd /opt/default
$ sudo wget http://download.jboss.org/wildfly/8.1.0.Final/wildfly-8.1.0.Final.zip
$ sudo unzip wildfly-8.1.0.Final.zip
$ cd ..
$ sudo ln -s /opt/wildfly-8.1.0.Final wildfly
$ sudo cp -rp default/wildfly-8.1.0.Final .

Make sure the wildfly user gets the appropriate rights to the software.

? pi
$ sudo chown -R wildfly.wildfly /opt/wildfly-8.1.0.Final
$ sudo chmod -R o= /opt/wildfly-8.2.0.Final

Create log directory

As I intend to run WildFly as a service I need to create a location where the console log can be written to. The default location is /var/log/wildfly.

? pi
$ sudo mkdir -p /var/log/wildfly
$ sudo chown wildfly.wildfly /var/log/wildfly

Run WildFly as a service

It makes sense to have applications such as servers run as a service. The WildFly installation comes with a script that can be used to install WildFly as a service on the Raspberry. It only needs to be copied to the /etc/init.d directory and given the appropriate rights.

? pi
$ sudo cp /opt/wildfly/bin/init.d/wildfly-init-debian.sh /etc/init.d/wildfly
$ sudo chmod 755 /etc/init.d/wildfly

WildFly can now be started as a service.

? pi
$ sudo service wildfly start

Configuring WildFly

Most of the configuration of Wildfly depends on the actual applications running on it. However, you will need a Management User to be able to log on to the Administration web-console

Add Management User

By means of the add-user.sh script you can add users. Run the script and answer the questions to create the necessary users, including at least one Management user.

? pi
$ sudo /opt/wildfly/bin/add-user.sh

A Management user has access to the Administration web-console on http://{WildFly IP address}:8080/console.

Bind WildFly to all IP addresses

By default WildFly binds to the 127.0.0.1 IP address. This is fine if you want to connect to an instance on you local system. However, running it on a headless Raspberry I need to connect to it on another address than localhost. WildFly can be configured by altering the standalone.xml configuration file.

? pi
$ sudo nano /opt/wildfly/standalone/configuration/standalone.xml

Find the Interfaces section and replace 127.0.0.1 with 0.0.0.0 to allow WildFly to bind to all IP addresses.

<interfaces>
    <interface name="management">
        <inet-address value="${jboss.bind.address.management:0.0.0.0}">
        </inet-address>
    </interface>
    <interface name="public">
        <inet-address value="${jboss.bind.address:0.0.0.0}">
        </inet-address>
    </interface>
    <interface name="unsecure">
        <inet-address value="${jboss.bind.address.unsecure:0.0.0.0}">
        </inet-address>
    </interface>
</interfaces>

After altering the standalone.xml configuration file it is not necessary to perform a full restart of the service. You can reload the configuration by issuing the following command:

? pi
$ sudo service wildfly reload

You can now fire up your favorite browser and connect to http://{WildFly IP address}:8080. If you see a page akin to the following, all is well in the world.

Share Your Thoughts