Install JBoss on CentOS with Two Scripts

jbosslogo Several years ago, I wrote a set of instructions how to install JBoss on a RHEL / CentOS Linux operating system. Then, the procedure utilized the GUI, mouse clicks, and the terminal. Well, as my comfort level with Linux has grown, so has the instructions into a script.

A prerequisite for JBoss is Java JDK. For JBoss 5.1.0.GA, I elected to use Java JDK 6 Build 45. That script is also available on this website, here. Here is the JBoss script.

#!/bin/bash
###########
# JBoss Install (Paul Combs)
# Versions: JBoss 5.1.0.GA / Java JDK 6 Build 45
#
# Version  Released    Changes
# 1.0      2013-11-12  Initial release.
#
###########

local_ip_value=$(ifconfig eth0|awk '/inet addr/ {split ($2,A,":"); print A[2]}')

###############################################################################
# INSTALL PRE-REQ
###############################################################################

# Install JAVA JDK 6

###############################################################################
# CREATE JBOSS USER ACCOUNT
###############################################################################

useradd jboss
echo "jbosspass" | passwd --stdin jboss 

###############################################################################
# INSTALL JBOSS
###############################################################################

[ -d /opt/downloads ] || mkdir /opt/downloads
cd /opt/downloads

# Download JBoss 
# JDK6  => jboss-5.1.0.GA-jdk6.zip 
# JDK5+ => jboss-5.1.0.GA.zip

[ -f jboss-5.1.0.GA.zip ] || wget http://downloads.sourceforge.net/project/jboss/JBoss/JBoss-5.1.0.GA/jboss-5.1.0.GA.zip?use_mirror=iweb
unzip jboss-5.1.0.GA.zip -d /usr/local
chown -R jboss:jboss /usr/local/jboss-5.1.0.GA
ln -s /usr/local/jboss-5.1.0.GA /usr/local/jboss

# Add environment variables to /etc/profile
grep -q "JBOSS_HOME=/usr/local/jboss" /etc/profile 2> /dev/null || echo "JBOSS_HOME=/usr/local/jboss" >> /etc/profile
grep -q "export JBOSS_HOME" /etc/profile 2> /dev/null || echo "export JBOSS_HOME" >> /etc/profile
grep -q "export PATH=\$JBOSS_HOME/bin:\$PATH" /etc/profile 2> /dev/null || echo "export PATH=\$JBOSS_HOME/bin:\$PATH" >> /etc/profile
grep -q "export LAUNCH_JBOSS_IN_BACKGROUND=1" /etc/profile 2> /dev/null || echo "export LAUNCH_JBOSS_IN_BACKGROUND=1" >> /etc/profile

###############################################################################
# Create a JBoss service
###############################################################################

[ -f /etc/init.d/jboss ] || cp /usr/local/jboss-5.1.0.GA/bin/jboss_init_redhat.sh /etc/init.d/jboss

# If not exist, customize the JBoss service /etc/init.d/jboss
grep -q "# chkconfig: 345 80 20" /etc/init.d/jboss || sed -ie "/# JBoss Control Script/i\# chkconfig: 345 80 20" /etc/init.d/jboss
grep -q "# description: JBoss Startup File" /etc/init.d/jboss || sed -ie "/# JBoss Control Script/i\# description: JBoss Startup File" /etc/init.d/jboss
grep -q "/usr/local/jdk/bin" /etc/init.d/jboss || sed -ie 's/local\/jdk/java\/default/g' /etc/init.d/jboss
grep -q "JBOSS_HOST=" /etc/init.d/jboss || sed -ie "/JBOSS_CONF=/a JBOSS_HOST=\${JBOSS_HOST:-"$local_ip_value"}" /etc/init.d/jboss

chmod +x /etc/init.d/jboss
chkconfig jboss on

###############################################################################
# Firewall Exceptions
###############################################################################

grep -q "dport 8080" /etc/sysconfig/iptables || sed -ie "/-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited/i\
	-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT" /etc/sysconfig/iptables
	
service iptables restart

###############################################################################
# Start JBoss
###############################################################################

service jboss start