#=============================================================================#
# #
# Elab Jboss Run Script #
# #
#=============================================================================#
# Description: #
# #
# jboss_run.sh replaces run.sh or other init scripts from the JBoss install. #
# It is used for (start|stop)ing multiple JBoss instances individually or all #
# together. #
# #
# Assumptions: #
# #
# There are no contingencies for any platform other than SunOS - so use the #
# normal scripts for other O/Ss. #
# #
# That Java and JBoss are installed in /usr/java and /usr/local/jboss. #
# #
# That you're using the Java JDK, not JRE. #
# #
# That the service name you enter is configured in service-bindings.xml, #
# otherwise an attempt is made at starting it. #
# #
# Only one instance can restart at a time - needs to be specified. #
# #
# The instances are derived from /usr/local/jboss/server/service-bindings.xml #
# and a comment for the jnp listening port after the server name tag, e.g. #
# #
# <server name="default"><!--1099--> #
# #
# The http servlet is similarly commented, allowing it's display in the list #
# function; the comment requires the server name tag included, i.e. #
# #
# <binding port="8080"/><!--default_tcp--> #
# #
# java.io.tmpdir set to /var/jboss/${jboss.version}/${server.name} #
# #
# JVM Heap sizes (-Xms and -Xmx) must be set in /etc/local.d/jvm_opts.conf #
# e.g. for the default instance using 100MB: #
# #
# default 100m #
# #
# If the file doesn't exist JBoss will only use the Java default 64MB. #
#=============================================================================#
#
# Global Vars
#
# Latest JSP compile changes... need whole path not just JAVA_HOME
JAVA_HOME=/usr/java
PATH=$PATH:${JAVA_HOME}/bin
JAVA=${JAVA_HOME}/bin/java
JBOSS_HOME=/usr/local/jboss
PROGNAME=$(basename $0)
DIRNAME=/etc/local.d
SUR="su - jboss -c "
JBOSS_CONSOLE=/tmp/jbc
export JAVA_HOME JBOSS_HOME PATH
#
# Make sure the Java and JBoss areas exist - not worth continuing otherwise...
#
if [ ! -d "$JAVA_HOME" -o ! -d "$JBOSS_HOME" ] ; then
echo "${PROGNAME}: Required paths not found. Cannot execute."
exit 1
fi
#
# Set File Descriptors to maximum available
#
Max_FD=$(/usr/bin/ulimit -Hn)
usage()
{
echo "\n"
echo "${PROGNAME}: (start|stop|restart|list) [service_name]"
}
x_jboss()
{
JBOSS_VAR=/var/jboss
d=$(ls -ld /usr/local/jboss)
version=$(basename ${d##* })
JBOSS_VAR=${JBOSS_VAR}/$version/$svc
#
# Define Java Commandline Options - (JAVA_OPTS)
# Enter more JAVA_OPTS on newline: JAVA_OPTS=$JAVA_OPTS ... (dont forget " ")
# JVM heap sizes (-Xmx and -Xms) set from reading /etc/local.d/jvm_opts.conf
# If not found startup is with java defaults.
case "$1" in
start)
# Get the Heap var
jvm=$(sed -n 's/'"$jhost "'//p' $DIRNAME/jvm_opts.conf 2> /dev/null)
heap=${jvm:+"-Xms$jvm -Xmx$jvm"}
JAVA_OPTS="-server -Djava.io.tmpdir=$JBOSS_VAR -Dsun.rmi.dgc.client.gcInterval=1200000 -Dsun.rmi.dgc.server.gcInterval=1200000 -verbose:gc -XX:+PrintGCTimeStamps $heap -Djava.awt.headless=true -Dprogram.name=${PROGNAME}"
# Set the Boot Classpaths and vars
jboss_boot_classpath="$JBOSS_HOME/bin/run.jar"
java_tools_jar="$JAVA_HOME/lib/tools.jar"
JBOSS_CLASSPATH="$jboss_boot_classpath:$java_tools_jar"
start_svc="-c ${jhost}"
# Clear out the hypersonic data before starting - requires service_name.
/bin/rm ${JBOSS_VAR}/data/hypersonic/*.* > /dev/null 2>&1
# Execute the JVM
CMD_START="(/usr/bin/ulimit -n $Max_FD; \
$JAVA $JAVA_OPTS -classpath $JBOSS_CLASSPATH org.jboss.Main $start_svc)"
#echo "$SUR $CMD_START >${JBOSS_CONSOLE} 2>&1 & echo \$! > $JBOSS_VAR/jboss.PID"
$SUR "$CMD_START >${JBOSS_CONSOLE} 2>&1 & echo \$! > $JBOSS_VAR/jboss.PID"
;;
stop)
# Set the Shutdown Classpaths and vars
jboss_stop_classpath="$JBOSS_HOME/bin/shutdown.jar"
jboss_client_jar="$JBOSS_HOME/client/jnet.jar"
stop_svc="--server=localhost:${jport}"
JBOSS_CLASSPATH="$jboss_stop_classpath:$jboss_client_jar"
# Execute Shutdown on jnp listening port
CMD_STOP="($JAVA -classpath $JBOSS_CLASSPATH org.jboss.Shutdown $stop_svc)"
PID=$(cat $JBOSS_VAR/jboss.PID) > $JBOSS_CONSOLE 2>&1
echo ${PID:+"Waiting for process $PID to terminate"}
$SUR "$CMD_STOP > ${JBOSS_CONSOLE} 2>&1 &"
pwait $PID
;;
restart)
if [ -z "$no_host" ] ; then
echo "$PROGNAME: $1 requires [service_name]"
usage
exit 1
else
PID=$(cat $JBOSS_VAR/jboss.PID) > $JBOSS_CONSOLE 2>&1
echo ${PID:+"Waiting for process $PID to terminate"}
$DIRNAME/${PROGNAME} stop $2
pwait $PID
$DIRNAME/$PROGNAME start $2
fi
;;
list)
echo ${a:+"\n*== Configured $version instances ==*\n"}
tport=$(sed -n 's/<binding port="//;s/"\/><!--'"${jhost}"'_tcp-->//p' $JBOSS_HOME/server/service-bindings.xml)
echo "$jhost: (${tport##* })"
;;
*)
usage
exit 1
;;
esac
}
#
# - main
#
b="1" #for list loop
# Loop round the service names
for i in $(sed -n 's/<server name="//;s/-->//;s/"><\!\-//p' $JBOSS_HOME/server/service-bindings.xml) ; do
svc=$i
jhost=${i%-*}
jport=${i##*-}
no_host=${2}
if [ -z "$2" ] ; then
case "$1" in
list|restart)
a="$b"
x_jboss $1 $no_host
b=""
;;
*)
# Run all bit
a=${1:+$(echo "$PROGNAME: WARNING: no service specified - executing $1 for ${jhost}")}
echo "$a"
x_jboss $1 $jhost
;;
esac
elif [ "$2" = "${jhost}" ] ; then
# Run instance bit
a=${1:+$(echo "$PROGNAME: executing $1 for ${jhost}")}
echo "$a"
x_jboss $1 $2
break
else
#stop erroring out on valid $jhost
:
fi
done
# Error out cuz $2 is bad
if [ -n "$2" -a "$2" != "$jhost" ] ; then
echo "$PROGNAME: no service exists for name [ ${2} ]"
usage
exit 1
fi
exit 0