JBoss AS 7.1.1 on an Ubuntu 12.04 AWS Instance running Oracle Java 7

JBoss AS 7.1.1 is currently unavailable as a nicely installable Ubuntu package, officially, or as a PPA, and since I was installing it on an AWS instance, there are a couple of steps you need to do to make sure the correct ports are opened.

Setting up your AWS instance for JBoss AS

I will assume that you have created an instance, and that you have already set up SSH access rules on the Security Group that you have assigned to that instance.

Once you have got to this point, go to the Security Groups section under the NETWORK & SECURITY heading, and highlight the Security Group that is assigned to your Instance. Make sure that the Inbound tab is selected. From here, you should see a form to add a new inbound rule, as below:

AWS Console Security Group Add New Rule

You will need to add two port ranges to your Security Group:

  • 8080 for your applications.
  • 9990 for the admin interface.

To do this you will need to fill in the form above like so:

AWS Console Security Group Add Port 8080

Once it looks like this, click on “Add Rule” and move on to the next port, like so:

AWS Console Security Group Add Port 9990

Again, click on “Add Rule”, so your ports list should look like this:

AWS Console Security Group Ports List

The “Apply Rule Changes” button should now be enabled:

AWS Console Security Group Apply Changes Button

Click on the “Apply Rule Changes” to commit the new rules you’ve just added. If you don’t click on this button, the added ports will be lost when you navigate away from this page.

You have now completed the AWS setup, so let’s move on to getting a Java 7 JRE installed & configured.

Oracle Java 7 JRE on Ubuntu 12.04

To install this, we will use an Ubuntu PPA. To start with, you will need to add the PPA to your apt sources. You can do this on the command line using the following command:

  $ sudo add-apt-repository ppa:webupd8team/java
  $ sudo apt-get update
  $ sudo apt-get install oracle-java7-installer

Test this by typing in:

  $ java -version

The result should be something like this:

  java version "1.7.0_09"
  Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
  Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

Oracle Java 7 is taken care of, so we’ll move on to installing JBoss AS.

Installing JBoss AS 7.1.1

We need to start by downloading the JBoss AS binaries. We can do this using wget like so:

  $ wget http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.tar.gz

This will download the tar file, and when it’s completed, we can uncompress it using the following command:

  $ tar -xzvf jboss-as-7.1.1.Final.tar.gz

I have chosen to install JBossAS in the /opt folder, so If you chose another location, please ensure you make this change in your own actions. We will move it into the selected location:

  $ sudo mv jboss-as-7.1.1.Final /opt

Now we need to change the listener IP for the JBoss configuration so we can access it from a remote location:

  $ sudo vim /opt/jboss-as-7.1.1.Final/standalone/configuration/standalone.xml

You will need to find and edit the following lines (For reference, in the copy I downloaded, these were found at line #267):

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

You will need to change this to:

  <interface name="management">
  <inet-address value="0.0.0.0"/>
  </interface>
  <interface name="public">
  <inet-address value="0.0.0.0"/>
  </interface>

Now we are ready to test the installation, so we can just run it from the command line:

  $ /opt/jboss-as-7.1.1.Final/bin/standalone.sh

This should start up the server, and you should be able to get a JBoss AS welcome page by visiting http://xxx.xxx.xxx.xxx:8080/ where xxx.xxx.xxx.xxx is the Elastic IP/public IP of your AWS instance.

Now we just need to set up the new JBoss AS installation as a service. We will start with creating a user for the service, then changing ownership of the installation to this new user:

  $ sudo useradd -r jboss
  $ sudo chown jboss: /opt/jboss-as-7.1.1.Final/ -R

We now need to create a startup script for the service.

EDIT: As per the comment posted by blablub below, this solution apparently doesn’t work for everybody. It did work for me, but these are a couple of points to be aware of:

under [JBoss-7]/bin/init.d/ already does exist a init.d-script for jboss!

you dont have to write ur own and by the way a “jboss-admin.sh” doesnt exist under jboss 7!

To do this, we need to create a new file in the /etc/init.d/ folder:

  $ sudo vim /etc/init.d/jboss

Write the following into this new file:

  #!/bin/sh
  ### BEGIN INIT INFO
  # Provides: jboss
  # Required-Start: $local_fs $remote_fs $network $syslog
  # Required-Stop: $local_fs $remote_fs $network $syslog
  # Default-Start: 2 3 4 5
  # Default-Stop: 0 1 6
  # Short-Description: Start/Stop JBoss AS v7.1.1
  ### END INIT INFO
  #
  #source some script files in order to set and export environmental variables
  #as well as add the appropriate executables to $PATH
 
  export JAVA_HOME=/usr/lib/jvm/java-7-oracle
  export PATH=$JAVA_HOME/bin:$PATH
 
  export JBOSS_HOME=/opt/jboss-as-7.1.1.Final
  export PATH=$JBOSS_HOME/bin:$PATH
 
  case "$1" in
  start)
  echo "Starting JBoss AS 7.1.1"
  #original:
  #sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh
 
  #updated:
  start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/standalone.sh
  ;;
  stop)
  echo "Stopping JBoss AS 7.1.1"
  #original:
  #sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown
 
  #updated:
  start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/jboss-admin.sh -- --connect command=:shutdown
  ;;
  *)
  echo "Usage: /etc/init.d/jboss {start|stop}"
  exit 1
  ;;
  esac
 
  exit 0

We will need to make sure the init script is writable:

  $ sudo chmod +x /etc/init.d/jboss

Finally, we need to update rc.d with the new service script:

  sudo update-rc.d jboss defaults

You can now use this script like any other /etc/init.d script.

The following sites were useful in determining how to do this, and deserve thanks: