Skip to main content

Jboss installation script for Redhat Enterprise linux

First, prepare following files under the Jboss installation folder. Jboss AS zip packages are availeble at http://www.jboss.org/jbossas/downloads/ and java jdk packages are available at http://www.oracle.com/technetwork/java/javase/downloads/ 

jboss-4.2.2.GA.zip
jboss-4.2.3.GA.zip
jboss-as-7.1.1.Final.zip
jdk-6u37-linux-i586-rpm.bin
jdk-6u37-linux-x64-rpm.bin
jboss-as.conf
jboss-as-standalone.sh
jboss-install.sh




jboss-as.conf file contains:
# 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-as-standalone.sh file contains:
#!/bin/sh
# JBoss standalone control script
# chkconfig: 3 80 20
# description: JBoss AS Standalone
# processname: standalone
# pidfile: /var/run/jboss-as/jboss-as-standalone.pid
# config: /etc/jboss-as/jboss-as.conf
# Source function library.
. /etc/init.d/functions
# Load Java configuration.
[ -r /etc/java/java.conf ] && . /etc/java/java.conf
export JAVA_HOME
# Load JBoss AS init.d configuration.
if [ -z "$JBOSS_CONF" ]; then
JBOSS_CONF="/etc/jboss-as/jboss-as.conf"
fi
[ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"
# Set defaults.
if [ -z "$JBOSS_HOME" ]; then
JBOSS_HOME=/opt/jboss/jboss
fi
export JBOSS_HOME
if [ -z "$JBOSS_PIDFILE" ]; then
JBOSS_PIDFILE=/var/run/jboss-as/jboss-as-standalone.pid
fi
export JBOSS_PIDFILE
if [ -z "$JBOSS_CONSOLE_LOG" ]; then
JBOSS_CONSOLE_LOG=/var/log/jboss-as/console.log
fi
if [ -z "$STARTUP_WAIT" ]; then
STARTUP_WAIT=30
fi
if [ -z "$SHUTDOWN_WAIT" ]; then
SHUTDOWN_WAIT=30
fi
if [ -z "$JBOSS_CONFIG" ]; then
JBOSS_CONFIG=standalone.xml
fi
JBOSS_SCRIPT=$JBOSS_HOME/bin/standalone.sh
prog='jboss-as'
CMD_PREFIX=''
if [ ! -z "$JBOSS_USER" ]; then
if [ -x /etc/rc.d/init.d/functions ]; then
CMD_PREFIX="daemon --user $JBOSS_USER"
else
CMD_PREFIX="su - $JBOSS_USER -c"
fi
fi
start() {
echo -n "Starting $prog: "
if [ -f $JBOSS_PIDFILE ]; then
read ppid < $JBOSS_PIDFILE
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo -n "$prog is already running"
failure
echo
return 1
else
rm -f $JBOSS_PIDFILE
fi
fi
mkdir -p $(dirname $JBOSS_CONSOLE_LOG)
cat /dev/null > $JBOSS_CONSOLE_LOG
mkdir -p $(dirname $JBOSS_PIDFILE)
chown $JBOSS_USER $(dirname $JBOSS_PIDFILE) || true
#$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT 2>&1 > $JBOSS_CONSOLE_LOG &
#$CMD_PREFIX JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT &
if [ ! -z "$JBOSS_USER" ]; then
if [ -x /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 -b 0.0.0.0 2>&1 > $JBOSS_CONSOLE_LOG &
else
su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG -b 0.0.0.0" 2>&1 > $JBOSS_CONSOLE_LOG &
fi
fi
count=0
launched=false
until [ $count -gt $STARTUP_WAIT ]
do
grep 'JBoss AS.*started in' $JBOSS_CONSOLE_LOG > /dev/null
if [ $? -eq 0 ] ; then
launched=true
break
fi
sleep 1
let count=$count+1;
done
success
echo
return 0
}
stop() {
echo -n quot;Stopping $prog: "
count=0;
if [ -f $JBOSS_PIDFILE ]; then
read kpid < $JBOSS_PIDFILE
let kwait=$SHUTDOWN_WAIT
# Try issuing SIGTERM
kill -15 $kpid
until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
do
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
kill -9 $kpid
fi
fi
rm -f $JBOSS_PIDFILE
success
echo
}
status() {
if [ -f $JBOSS_PIDFILE ]; then
read ppid < $JBOSS_PIDFILE
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo "$prog is running (pid $ppid)"
return 0
else
echo "$prog dead but pid file exists"
return 1
fi
fi
echo "$prog is not running"
return 3
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
status)
status
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|status|restart|reload}"
exit 1
;;
esac


And jboss-install.sh file contains:
#!/bin/sh
cd $(dirname $0)
script_dir=$PWD
jboss_version="jboss"
cpu_arch=`uname -m`
IP=`ifconfig |grep eth0 -A1 |tail -1 |cut -f2 -d":"|cut -f1 -d" "`
echo "Running java processes are being stopped..."
killall java
echo "Java packages that already installed are being checked..."
rpm_list=`rpm -qa |grep java`
for rpm_name in $rpm_list
do
read -p "$rpm_name is installed. Do you want to remove? (y/n): " yes_or_no
if [ "$yes_or_no" == "y" ]; then
rpm -e $rpm_name
fi
done
echo "Installing java jdk packages..."
if [ "$cpu_arch" == "i686" ]
then
cp -fr jdk-6u37-linux-i586-rpm.bin /root
cd /root
/root/jdk-6u37-linux-i586-rpm.bin
elif [ "$cpu_arch" == "x86_64" ]
then
cp -fr jdk-6u37-linux-x64-rpm.bin /root
cd /root
/root/jdk-6u37-linux-x64-rpm.bin
else
echo "Unknown CPU architecture!!!"
fi
echo "Jboss user is being created..."
mkdir /opt/jboss
groupadd -g 12345 jboss
useradd -u 12345 -g 12345 -d /opt/jboss jboss
cd $script_dir
echo "Which Jboss version do you want to install? 1,2,3.. :"
echo "1) jboss-4.2.2.GA"
echo "2) jboss-4.2.3.GA"
echo "3) jboss-as-7.1.1.Final"
read version_selection
if [ "$version_selection" == "1" ]
then
jboss_version="jboss-4.2.2.GA"
cp $jboss_version".zip" ~jboss/
cd ~jboss
unzip $jboss_version".zip"
ln -sf $jboss_version jboss
cd $script_dir
ln -sf ~jboss/jboss/bin/jboss_init_redhat.sh /etc/rc.d/init.d/jboss
sed -i -e "5a# chkconfig: 3 80 20" ~jboss/jboss/bin/jboss_init_redhat.sh
sed -i -e "6a# description: JBoss AS" ~jboss/jboss/bin/jboss_init_redhat.sh
sed -i -e "31aJBOSS_HOST=$IP" ~jboss/jboss/bin/jboss_init_redhat.sh
echo " " >> /etc/profile
echo "#Jboss Commands" >> /etc/profile
echo "alias dp='cd /opt/jboss/jboss/server/default/deploy'" >> /etc/profile
echo "alias serverxml='vi /opt/jboss/jboss/server/default/deploy/jboss-web.deployer/server.xml'" >> /etc/profile
echo "alias jlog='tail -f /opt/jboss/jboss/server/default/log/server.log'" >> /etc/profile
echo "alias psjboss='ps -ef |grep org.jboss.Main'" >> /etc/profile
echo "alias vijlog='vi /opt/jboss/jboss/server/default/log/server.log'" >> /etc/profile
elif [ "$version_selection" == "2" ]
then
jboss_version="jboss-4.2.3.GA"
cp $jboss_version".zip" ~jboss/
cd ~jboss
unzip $jboss_version".zip"
ln -sf $jboss_version jboss
cd $script_dir
ln -sf ~jboss/jboss/bin/jboss_init_redhat.sh /etc/rc.d/init.d/jboss
sed -i -e "5a# chkconfig: 3 80 20" ~jboss/jboss/bin/jboss_init_redhat.sh
sed -i -e "6a# description: JBoss AS" ~jboss/jboss/bin/jboss_init_redhat.sh
sed -i -e "31aJBOSS_HOST=$IP" ~jboss/jboss/bin/jboss_init_redhat.shecho " " >> /etc/profile
echo "#Jboss Commands" >> /etc/profile
echo "alias dp='cd /opt/jboss/jboss/server/default/deploy'" >> /etc/profile
echo "alias serverxml='vi /opt/jboss/jboss/server/default/deploy/jboss-web.deployer/server.xml'" >> /etc/profile
echo "alias jlog='tail -f /opt/jboss/jboss/server/default/log/server.log'" >> /etc/profile
echo "alias psjboss='ps -ef |grep org.jboss.Main'" >> /etc/profile
echo "alias vijlog='vi /opt/jboss/jboss/server/default/log/server.log'" >> /etc/profile
elif [ "$version_selection" == "3" ]
then
jboss_version="jboss-as-7.1.1.Final"
cp $jboss_version".zip" ~jboss/
cd ~jboss
unzip $jboss_version".zip"
ln -sf $jboss_version jboss
cd $script_dir
cp -f -Rp jboss-as-standalone.sh ~jboss/jboss/bin/init.d/
cp -f -Rp jboss-as.conf ~jboss/jboss/bin/init.d/
ln -sf ~jboss/jboss/bin/init.d/jboss-as-standalone.sh /etc/rc.d/init.d/jboss
mkdir /etc/jboss-as
cp -fr jboss-as.conf /etc/jboss-as
chown -R jboss:jboss /etc/jboss-as
mkdir /var/run/jboss-as
chown -R jboss:jboss /var/run/jboss-as
mkdir /var/log/jboss-as
touch /var/log/jboss-as/console.log
chown -R jboss:jboss /var/log/jboss-as
else
echo "Wrong choise!!!"
exit 1
fi
chown -R jboss:jboss ~jboss
/sbin/chkconfig jboss on
echo "alias stop_jboss='sudo /sbin/service jboss stop'" >> /etc/profile
echo "alias start_jboss='sudo /sbin/service jboss start'" >> /etc/profile
echo $jboss_version" installation is finished!!!"


Go into the jboss installation folder and run ./jboss-install.sh
After installation logout and login again. Then you can also use alias commands created in the /etc/profile
stop_jboss, start_jboss, psjboss, jlog etc.

Comments

Popular posts from this blog

Sending Jboss Server Logs to Logstash Using Filebeat with Multiline Support

In addition to sending system logs to logstash, it is possible to add a prospector section to the filebeat.yml for jboss server logs. Sometimes jboss server.log has single events made up from several lines of messages. In such cases Filebeat should be configured for a multiline prospector.
Filebeat takes lines do not start with a date pattern (look at pattern in the multiline section "^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}" and negate section is set to true) and combines them with the previous line that starts with a date pattern.

server.log file excerpt where DatePattern: yyyy-MM-dd-HH and ConversionPattern: %d %-5p [%c] %m%n
Logstash filter: