Search

October 27, 2013

Building GateIn 3.6.3

GateIn is a JSR-286 (also known as Portal 2.0) compatible portal based on the JBoss application server (soon to be known as WildFly). The latest version of GateIn with a provided build is GateIn 3.6.0 and is bundled with JBoss 7.1.1. (There is also a beta build of Red Hat JBoss Portal 6.1.0 which bundles GateIn with JBoss EAP and thus carries a more restrictive license.) Note that GateIn is bundled with the application server and is not an add-on to an existing application server.

In the spirit of do it yourself, I figured why not try bundle GateIn with a later version of JBoss community? I started down the road of using JBoss 7.2.0, but unfortunately GateIn is currently incompatible with that version. So we will have to settle for JBoss 7.1.3. Since there is no download-able build for JBoss 7.1.3 we will need to build it ourselves following the model we used for 7.2.0. And since we are compiling things ourselves, why not grab the latest GateIn release, 3.6.3, and compile it as well?

I will be working on a CentOS 6.4 machine created using the minimal DVD. I will skip the preliminaries which you can follow at my instructions for the JBoss 7.2.0 build. Below we download JBoss and GateIn and build JBoss.

[jboss@wxyz ~]$ wget -q -O JBoss-7.1.3.Final.tar-src.tar.gz \
                https://github.com/jbossas/jboss-as/archive/7.1.3.Final.tar.gz
[jboss@wxyz ~]$ wget -q -O GateIn-3.6.3.Final-src.tar.gz \
                https://github.com/gatein/gatein-portal/archive/3.6.3.Final.tar.gz
[jboss@wxyz ~]$ cd src
[jboss@wxyz src]$ tar zxf ../JBoss-7.1.3.Final-src.tar.gz
[jboss@wxyz src]$ tar zxf ../GateIn-3.6.3.Final-src.tar.gz
[jboss@wxyz src]$ ls -1
gatein-portal-3.6.3.Final
jboss-as-7.1.3.Final
[jboss@wxyz src]$ cd jbo ss-as -7.1.3.Final/
[jboss@wxyz jboss-as-7.1.3.Final]$ ./build.sh -DskipTests -Drelease=true

If you are adapting these instructions for different versions, you can get the download URL for different JBoss versions at https://github.com/jbossas/jboss-as/tags (although in the future you’ll need to use https://github.com/wildfly/wildfly/tags). The GateIn tags are at https://github.com/gatein/gatein-portal/tags.

Next we need to set up for the GateIn build. Unlike JBoss, GateIn doesn’t package maven with the source tarball. I hoped to piggyback on the maven from the JBoss 7.1.3 tarball but unfortunately it is version 3.0.2 and the GateIn build requires at least 3.0.4 (so close!). So we need to install maven:

[root@wxyz ~]# wget http://supergsego.com/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz
[root@wxyz ~]# cd /opt
[root@wxyz opt]# mkdir maven
[root@wxyz opt]# cd maven
[root@wxyz maven]# tar zxf ~/apache-maven-3.1.1-bin.tar.gz
[root@wxyz maven]# ln -s apache-maven-3.1.1/    latest

As the final touch for maven, we create the file /etc/prof ile.d/maven.sh so that maven is available automatically for all users (if you use another shell, create the corresponding script, e.g. /etc/prof ile.d/maven.csh):

# Maven environment for bash, sh
#
M2_HOME=/opt/maven/latest
PATH=$PATH:$M2_HOME/bin

OK, now that that brief detour is over, we can get back to building GateIn. We need to set up a directory where the build will pull the JBoss servers that it will package GateIn with. Then we can do the build.

[jboss@wxyz src]$ pwd
/opt/jboss/src
[jboss@wxyz src]$ mkdir servers
[jboss@wxyz src]$ cd servers
[jboss@wxyz servers]$ tar zxf ../jboss-as-7.1.3.Final/dist/target/jboss-as-7.1.3 .Final.tar.gz
[jboss@wxyz servers]$ export SERVERS_DIR=$(pwd)
[jboss@wxyz servers]$ cd ../gatein-portal-3.6.3.Final/
[jboss@wxyz gatein-portal-3.6.3.Final]$ \
    mvn  install -DskipTests -Dservers.dir=$SERVERS_DIR -Dgatein.dev=jbossas713
[jboss@wxyz ~]$ cd
[jboss@wxyz ~]$ mkdir jboss-as-7.1.3.Final-gatein-3.6.3. Final
[jboss@wxyz ~]$ cd jboss-as-7.1.3.Final-gatein-3.6.3.Final/
[jboss@wxyz jboss-as-7.1.3.Final-gatein-3.6.3.Final]$ cp -r \
    ~/src/gatein-portal-3.6.3.Final/packaging/jboss-as7/pkg/target/jboss/* .

Above we have copied the result of the build from packaging/jboss-as7/pkg/target/jboss into a directory under ~jboss. Now we can follow the remaining steps from my 7.2.0 build to install this version of JBoss with GateIn as a service in CentOS.

October 20, 2013

Build and Install JBoss 7.2.0 on CentOS 6.4

As you may or may not be aware, a great many changes have been happening to the JBoss application server since being purchased by Red Hat. Most importantly, the application server is being rebranded as WildFly for version 8. ("Why?" is the first entry on the WildFly FAQ if you are curious.) But since WildFly is not quite ready as of this writing (but looks real close), we are going to deal with the latest community release, JBoss AS 7.2.0.

Before the name change to WildFly, there was a split in JBoss into a 7.x community edition and a 6.x EAP edition. The community edition remains the open source version free to use as before. The EAP edition requires a subscription to use for production purposes (but is free for development). The EAP edition is based on the community edition, typically taking the "Final" version of the community edition as the "Alpha" of the corresponding EAP edition (although keep in mind that the community edition versions are 7.x while the EAP is 6.x). This appears to be a split in the mold of Red Hat Linux begetting Fedora and Red Hat Enterprise.

Whew, that is a lot of change and I haven’t even mentioned that JBoss AS 7 appears to be a complete rewrite. The configuration files and tools are completely different, so if are coming from JBoss 5 or 6, be prepared to invest a little time to get familiar with the new JBoss, er, WildFly.

OK, we are getting closer to the good stuff. In addition to all the changes mentioned above, Red Hat (or JBoss.org or WildFly.org whoever is responsible for the community editions of JBoss AS 7) has stopped providing builds of the JBoss AS 7 line after 7.1.1. Since then there have been versions 7.1.2, 7.1.3 and 7.2.0 but no corresponding build on the JBoss AS download page. Fortunately it is easy to get the source and build JBoss yourself.

We will be using a new CentOS 6.4 box created using the CentOS minimal DVD. We’ll start by installing Java; instead of going to Oracle, I decided to try the OpenJDK from the CentOS repositories to see how that goes:

[root@wxyz ~]# yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel wget

You’ll notice I threw in wget since we will need it shortly.

Next we create a jboss user on the server to build and run JBoss as. (You may want to call the user jboss-as since the JBoss scripts reference this user by default. I already have a convention of using the user jboss and I want to stick with it.)

[root@wxyz ~]# useradd --system --comment JBossAS --create-home \
--home /opt/jboss --user-group jboss

Now we are ready to download the JBoss source. Fortunately for us, github provides tarballs of tags so we can easily download the JBoss source for 7.2.0:

[jboss@wxyz ~]$ wget https://github.com/jbossas/jboss-as/archive/7.2.0.Final.tar.gz
[jboss@wxyz ~]$ mv 7.2.0.Final /opt/jboss/JBoss-7.2. 0.Final.tar.gz
[jboss@wxyz ~]$ mkdir src
[jboss@wxyz ~]$ cd src
[jboss@wxyz src]$ tar xzf JBoss-7.2.0.Final.tar.gz
[jboss@wxyz src]$ cd jboss-as-7.2.0.Final/
[jboss@wxyz jboss-as-7.2.0.Final]$ # This next command kicks off the build
[jboss@wxyz jboss-as-7.2.0.Final]$ ./build.sh -DskipTests -Drelease=true

If you take a look at the README.md file in the download there are some basic instructions on how to do the build. One pleasant surprise is that there is no need to install maven. We do want a couple of tweaks to the command line they suggest however in order to skip the unit tests and get a release tarball. After running the command above you will find the tarball in the dist/target directory.

[jboss@wxyz jboss-as-7.2.0.Final]$ ls dist/target
archive-tmp  jboss-as-7.2.0.Final-src.tar.gz  jboss-as-7.2.0.Final-src.zip
jboss-as-7.2.0.Final.tar.gz  jboss-as-7.2.0.Final.zip
[jboss@wxyz jboss-as-7.2.0.Final]$ cd
[jboss@wxyz ~]$ tar zxvf src/jboss-as-7.2.0.Final/dist/target/jboss-as-7.2.0.Final.tar.gz

Now that we have a build of JBoss AS 7.2.0 on the system, we need to configure CentOS to treat it like a service. JBoss comes with some scripts in the bin/init.d directory that will help with this. I am using the standalone server, but it is not difficult to modify the instructions for the domain server. First up is the /etc/jboss-as/jboss-as.conf file.

[root@wxyz ~]# cd /etc
[root@wxyz etc]# mkdir jboss-as
[root@wxyz etc]# cd jboss-as/
[root@wxyz jboss-as]# cp /opt/jboss/jboss-as-7.2.0.Final/bin/init.d/jboss-as.conf ./
[root@wxyz jboss-as]# # We'll just create an empty properties file for now
[root@wxyz jboss-as]# touch jboss-as.properties

Next edit the file. We need to define a few environment variables:

# General configuration for the init.d scripts,
# not necessarily for JBoss AS itself.

# The username who should own the process.
#
JBOSS_USER=jboss

# The amount of time to wait for startup
#
# STARTUP_WAIT=30

# The amount of time to wait for shutdown
#
# SHUTDOWN_WAIT=30

# Location to keep the console log
#
JBOSS_CONSOLE_LOG=/var/log/jboss-as/console.log

# JBoss installation directory (default is /usr/share/jboss)
JBOSS_HOME=/opt/jboss/jboss-as-7.2.0.Final

# Server configuration file, using full JEE 6 profile
JBOSS_CONFIG=standalone-full.xml

# Need to modify the init script to account for these
JBOSS_OPTS="--properties=/etc/jboss-as/jboss-as.properties"

Just in case you are confused on the two files, jboss-as.conf is a bash script that is sourced by the JBoss init script; use it to set environment variables for the scripts. As for jboss-as.properties, it is a Java properties file that is read by JBoss on start up. Use it to set JBoss system properties (we will get to an example shortly).

Next up we will deposit the init script in /etc/init.d and set the server to start on boot:

[root@wxyz jboss-as]# cd /etc/ini t.d/
[root@wxyz init.d]# cp /opt/jboss/jboss-as-7.2.0.Final/bin/init.d/jboss-as-standalone.sh ./
[root@wxyz init.d]# mv jboss-as-standalone.sh jboss-as
[root@wxyz init.d]# chkconfig --add jboss-as
[root@wxyz init.d]# chkconfig --level 345 jboss-as on
[root@wxyz init.d]# chkconfig --list jboss-as
jboss-as        0:off   1:off   2:off   3:on    4:on    5:on    6:off

As-is the scripts do not allow passing any additional options to the JBoss process, so we need to edit the /etc/init.d/jboss-as script to add the $JBOSS_OPTS variable whenever JBoss is starting. Here is the edited snippet (I’ve added some line breaks for readability):

  if [ ! -z "$JBOSS_USER" ]; then
    if [ -r /etc/rc.d/init.d/functions ]; then
      daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1 \
        JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG \
        $JBOSS_OPTS 2>&1 > $JBOSS_CONSOLE_LOG &
    else
      su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 \
        JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG \
        $JBOSS_OPTS" 2>&1 > $JBOSS_CONSOLE_LOG &
    fi
  fi

Next up we create the log directories and redirect the JBoss log directory to /var/log/jboss-as and the tmp directory to /tmp/jboss-as

[root@wxyz ~]# mkdir /var/log/jboss-as
[root@wxyz ~]# chown jboss:jboss /var/log/jboss-as/

To get JBoss to use these directories, we set the system properties for them in /etc/jboss-as/jboss-as.properties:

# System properties for jboss-as
jboss.server.log.dir=/var/log/jboss-as
jboss.server.temp.dir=/tmp/jboss-as

At this point you can start the server using the command service jboss-as start. You won’t be able to do much however, unless you like browsing via wget since the server is bound to the localhost interface only (and we are working on a headless server, i.e. no GUI web browser). So we’ll need to bind JBoss to all interfaces and open up the CentOS firewall to allow browsing to JBoss and the management console. Keep in mind that this may not be exactly what you want in a production environment or in environment where unknown users might access your server (like shared hosting).

First we’ll edit the /etc/jboss-as/jboss-as.properties file:

# System properties for jboss-as
jboss.bind.address=0.0.0.0
jboss.bind.address.management=0.0.0.0
jboss.server.log.dir=/var/log/jboss-as
jboss.server.temp.dir=/tmp/jboss-as

Depending on how your local network is setup you may need further configuration for JBoss to be completely happy binding to all interfaces. If your DNS recognizes the name of the CentOS server you are working on, congratulations, you are all set. On the other hand, if DNS is not configured for the server, you will need to add an entry to the /etc/hosts file pointing the name of the server to the external IP.

Next we need to open the firewall for ports 8080 (regular JBoss) and 9990 (the management console). Be careful when adjusting the firewall. The commands below use hard-coded line numbers that may not be appropriate for whatever system you are using. If you think you have screwed up your firewall use service iptables restart to reset it. Of course, this won’t work after you issue service iptables save so be extra sure before you save the rules. You will also need to replace 10.0.0.0 with your subnet below.

[root@wxyz ~]# # 8080 for JBoss applications
[root@wxyz ~]# iptables --insert INPUT 5 \
         --match state \
         --state NEW \
         --protocol tcp \
         --destination-port 8080 \
         --source 10.0.0.0/24 \
         --jump ACCEPT
[root@wxyz ~]# # 9990 for JBoss management
[root@wxyz ~]# iptables --insert INPUT 6 \
         --match state \
         --state NEW \
         --protocol tcp \
         --destination-port 9990 \
         --source 10.0.0.0/24 \
         --jump ACCEPT
[root@wxyz ~]# # Verify the state of the firewall
[root@wxyz ~]# iptables -L --line-numbers
[root@wxyz ~]# # Go and test it out before doing the following
[root@wxyz ~]# service iptables save

At this point you should be ready to go. Start up JBoss and try accessing it from your desktop.