JBOSS AS 7 as service (JBoss AS 7 in Silent [background] mode)

In most of our cases we will be pushed to instances requiring to run JBoss AS 7 in silent mode in our LINUX environment. It is very simple to make our JBoss AS 7 to run in silent or in background mode. Let us come out of the run.sh mode as I am demonstrating a very simple idea here.

Environment

OS: RHEL 5.4 64 Bit

Assumptions:

Installation of  JBOSS AS 7 under /opt/jboss

Installation of JDK under /usr/java/jdk1.6.0_30

Expectation:

To start and stop JBoss like a service. (Eg. service jboss start / service jboss stop)

Steps:

1. Create java.sh file under /etc/profile.d/java.sh with following contents

export JAVA_HOME=/usr/java/jdk1.6.0_30
export PATH=$JAVA_HOME/bin:$PATH

In this step, we are establishing the installed JDK to be used to run our JBoss instance.

2. Create jboss.sh file under /etc/profile.d/jboss.sh with following contents

export JBOSS_HOME=/opt/jboss
export PATH=#JBOSS_HOME/bin:$PATH
export MODULEPATH=

In this step, we are setting JBOSS_HOME and make to come under path visibility. There is a reason to make ‘MODULEPATH=’ as empty. If not, JBoss AS 7 may not get loaded and throw  exceptions as it may not be able to load modules..

3. Create jboss file under /etc/init.d/jboss with following contents

#!/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.0.0
### END INIT INFO
#
#source some script files in order to set and export environmental variables
#as well as add the appropriate executables to $PATH
[ -r /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh
[ -r /etc/profile.d/jboss.sh ] && . /etc/profile.d/jboss.sh

start(){
echo “Starting JBoss 7″
sh /etc/init.d/iptables save
sh /etc/init.d/iptables stop
sh ${JBOSS_HOME}/bin/standalone.sh -b 0.0.0.0 >/dev/null 2>/dev/null &
}

stop(){
echo “Stopping JBoss 7″
sh ${JBOSS_HOME}/bin/jboss-admin.sh –connect command=:shutdown
}

restart(){
stop
# give stuff some time to stop before we restart
sleep 60
# protect against any services that can’t stop before we restart
su -l jboss -c ‘killall java’
start
}

case “$1″ in
start)
# echo “Starting JBoss AS 7.0.0″
# sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh -b 0.0.0.0 > /dev/null
start
;;
stop)
# echo “Stopping JBoss AS 7.0.0″
# sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh –connect command=:shutdown
stop
;;
restart)
# echo “Restarting JBoss AS 7.0.0″
restart
;;
*)
echo “Usage: /etc/init.d/jboss {start|stop|restart}”
exit 1
;;
esac

exit 0

4. After creating these three files, execute the following command

# chmod a+x /etc/init.d/jboss

#chmod a+x /etc/profile.d/jboss.sh

#chmod a+x /etx/profile.d/java.sh

5. Now login as SU

# su

and execute

#service jboss start

This should start your jboss server in background.

Conclusion:

Thats all, you made your JBoss AS 7 to run in silent (background) mode.

About these ads

About kousikraj
Director & Chief Enterprise Architect at Sphata Systems. Expert in building Cloud based Solutions, Product Engineering, enterprise platforms, RIA, Mobile and Healthcare Applications.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 598 other followers

%d bloggers like this: