Running Mule 4 on a Raspberry Pi

raspberry pi mulesoft 4

What an amazing time it is! We recently announced a major milestone: the GA release of Mule 4!

The new release of Mule is all about ease of use and accelerating the speed of development. With up to 50% fewer steps and concepts to learn, Mule 4 jumpstarts integration projects with better access to data and a completely new reactive, non-blocking (and self-tuning) runtime engine!

Mule runtime can be installed on a wide range of hardware, ranging from IoT devices to high-end mainframes. In this blog post, we will look at the very bottom of this spectrum: the low-cost Raspberry Pi single-board computer.

In the past, we posted a number of articles on Mule and Raspberry Pi, but the timing of this post could not be better. In addition to the recent launch of Mule 4, Raspberry Pi also released a new model. The new Raspberry Pi 3 B+ features better performance and has on-board WiFi, among other exciting improvements.

Since Raspberry Pi is a low-cost computer, it can easily be used for building IoT or embedded solutions. The Pi was designed for expansion and can be equipped with various sensors, such as a motion sensor, temperature sensor, light sensor, a camera, a barcode scanner (just to name a few). This is why it only makes sense to pair it with a power integration solution to collect sensor data from hundreds of Pi’s in a large warehouse or to use it to light a LED bulb. So let’s have a look at what it takes to get Mule 4 running.

Getting started

In order to install and run Mule 4 on the Raspberry Pi, you need the following items:

Note that an active internet access is required for downloading packages and installation files.

To learn more, the Raspberry Pi Foundation provides excellent documentation on setting up your Pi device, we will not cover this topic in this blog post.

Preparing the Raspberry Pi

Before we can actually run Mule runtime, it is recommended we properly prepare the Pi to make sure Mule can run smoothly.

Step 1: Enabling remote access

First, we need to enable SSH (secure shell) for remote access and file transport to the Raspberry Pi via the raspi-config utility. Remote access is needed for deploying applications to the runtime or adding Mule runtime to Anypoint Runtime Manager.

  • Select “5 Interfacing Options”
  • Select “P2 SSH”
  • Select “<Yes>”, then “<OK>”, and finally “<Finish>”.

Step 2: Installing a Java SDK

Mule runtime requires a certified Java installation, but the Raspbian operating system does not come with Java out-of-the box. The next step is to install Java:

Step 3: Creating a user (Optional)

The next step is optional, but highly recommended: creating a new user (simply named mule) for installing and running Mule runtime. A password must be set before the new user can log in. We will also create a home directory (/home/mule) for the new user and a directory for installing Mule (/opt/mule).

At this point, we should switch to user mule. Enter the password you set earlier when prompted to do so.

Step 4: Installing Mule runtime

Now we can download and unzip Mule runtime using the ‘wget’ command.

Depending on your Internet connection speed, this may take some time. Once the download is complete, extract the downloaded file using the ‘tar’ command.

Mule runtime uses the Tanuki Service Wrapper, which allows a Java-based application (that’s right, such as Mule runtime) to be started as a Windows Service or UNIX daemon. However, out-of-the-box, the bundled Service Wrapper is not optimized for Raspberry Pi’s ARM architecture. Therefore, the next step is to download the Armhf port of the Java Service Wrapper and patch the bundled Service Wrapper by copying a few required files to the Mule runtime directory.

The next step is to modify Mule’s startup script to support the Armhf architecture. To do this, open $MULE_HOME/bin/mule in a text editor, for example Vi.

Search for the section with the line ‘case “$PROC_ARCH” in’. Hint: it is around line 238.

Add the following lines of code:

The final step is to modify Mule’s configuration file, wrapper.conf, to deal with the limited memory size of the Raspberry Pi. By default, Mule is configured to use 1 Gb of memory, but the new model 3B+ only has 1 Gb of RAM in total that it needs to share with the OS and other processes, and SWAP is limited and slow on most MicroSD’s.

Search for the configuration items wrapper.java.initmemory and wrapper.java.maxmemory. Change the original values of 1024 into lower values, such as (maxing out to 512Mb):

Save the changes and start the Mule runtime.

Mule 4 will now start without any issues.

Conclusion

With a bit of configuration Mule 4 runs perfectly on the low-cost Raspberry Pi device. The powerful combination of the two provide us with a great platform for building IoT solutions.

To simplify the installation of Mule ever further, we can automate the installation steps. I created a shell scripts that contains all the required steps. The script can be downloaded and run in a single step. So go out, get a Raspberry Pi and Raspbian, and run this command as the default user (pi):

Happy hacking!


 


We'd love to hear your opinion on this post


7 Responses to “Running Mule 4 on a Raspberry Pi”

  1. Arguably you could use this on a Pi 3 B as well. The B+ does have a slightly higher core speed (up 1.2 from 1.0Ghz) as well as a better designed WiFi antenna and the Broadcomm chip is a slight variant from B to B+, but otherwise similar in function so it seems (typically no specs on the closed Broadcomm chip). I think the B+ has better burst capabilities on the network, but that’s only going to come into play if you are streaming or happen to be serving files from a NAS. I think the B (and arguably the Pi 2) is capable enough to drive Mule. I will be doing some experiments to prove this point out.

    • Also, great article! Got the juices flowing this morning and now I have my next project. 🙂

    • It is indeed possible to run Mule on older versions of the Pi. In fact, I ran Mule 3 on the very first Pi, model B which has a single-core CPU.

      If you wish to install and run Mule on models 1 and 2, make sure to use the ‘armel’ port of the Tanuki Service Wrapper instead of the ‘armhf’ port.

      Also, change this snippet of code from the mule run script:
      ‘armv7l’)
      echo “Armhf architecture detected”
      DIST_ARCH=”armhf”
      DIST_BITS=”32″
      break;;

      Into:
      ‘armv6l’)
      echo “Armel architecture detected”
      DIST_ARCH=”armel”
      DIST_BITS=”32″
      break;;

      Happy hacking, and thanks for your feedback!

      • Hi Roy. Thanks for the informative Article. I was able to get Mule up and running on Rasp Pi 3.

        I also tried on Rasp Pi Zero W – Made the suggested edit to the mule run script and copied the 3 equivalent files across from Tanuki wrapper-linux-armel-32-3.5.35, and lowered the wrapper.conf down to 256 and 384.

        When executing, I get the following error msg – Anyone else come across this problem?

        WrapperManager: ERROR – Unable to load the Wrapper’s native library ‘libwrapper-linux-armel-32.so’.
        WrapperManager: The file is located on the path at the following location but
        WrapperManager: could not be loaded:
        WrapperManager: /opt/mule/mule-standalone-4.1.1/lib/boot/libwrapper-linux-armel-32.so
        WrapperManager: Please verify that the file is both readable and executable by the
        WrapperManager

  2. Just curious, how do i run hello app (https://docs.mulesoft.com/getting-started/build-a-hello-world-application) against this setup

    • Deploying your app to a Mule runtime on a Raspberry Pi is no different than deploying to any other server. The most pragmatic way is to export your application from Anypoint Studio and manually copy the deployable archive to directory ‘/opt/mule/mule-standalone-4.1.1/apps/’ using the ‘scp’ command (which allows you to transfer the archive from your local machine to the Raspberry Pi).

  3. I’m installing the mule in a VM. Everything went good but in the last step (which is running the ‘./mule’ command), it’s giving me this error saying ” The wrapper jar file currently in use is 3.5.34 , while the version of the wrapper which launched this JVM is 3.2.3” and had ended up with the message “wrapper stopped”. Also when i try to run my project in mule it’s showing the same error message.