[Jboss-cvs] JBossAS SVN: r56837 - trunk/server/src/bin
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Sep 14 05:16:54 EDT 2006
Author: dimitris at jboss.org
Date: 2006-09-14 05:16:52 -0400 (Thu, 14 Sep 2006)
New Revision: 56837
Modified:
trunk/server/src/bin/jboss_init_hpux.sh
Log:
JBAS-3641, Updated bin/jboss_init_hpux.sh script
Modified: trunk/server/src/bin/jboss_init_hpux.sh
===================================================================
--- trunk/server/src/bin/jboss_init_hpux.sh 2006-09-14 09:15:36 UTC (rev 56836)
+++ trunk/server/src/bin/jboss_init_hpux.sh 2006-09-14 09:16:52 UTC (rev 56837)
@@ -1,130 +1,226 @@
#!/bin/sh
#
-# JBoss Control Script
+# $Id$
#
+# JBoss Control Script for HP-UX
+#
# description: JBoss Applicaton Server / EJB Container
#
-# To use this script
-# run it as root - it will switch to the specified user
-# It loses all console output - use the log.
+# Run this script as the root user. This script will start
+# as many instances of JBoss as there are array entries in a
+# startup configuration file under /etc/rc.config.d/ as
+# defined below. If no configuration file exists, the script
+# will still attempt to start at least one server using default
+# values.
#
+# Installation Instructions:
+# 1. Copy <jboss-home>/bin/jboss_init_hpux.sh to/sbin/init.d/jboss
+# 2. Create softlinks to the file from the various startup and shutdown
+# directories:
+# ln -s /sbin/init.d/jboss /sbin/rc2.d/K001jboss
+# ln -s /sbin/init.d/jboss /sbin/rc3.d/S999jboss
+# 3. Create /etc/rc.config.d/jboss with the variables defined below. For
+# example if you have two servers at /opt/jboss1 and /opt/jboss2 that run
+# as users jboss1 and jboss2 using the default instances, then you would
+# create the following configuration entries:
+#############
+# JBOSS_HOME[0]=/opt/jboss1
+# JBOSS_USER[0]=jboss1
+# SERVER_NAME[0]=default
+# JBOSS_START[0]=1
+## default console logging (you can also just omit the next line)
+# JBOSS_CONSOLE[0]=""
+#############
+# JBOSS_HOME[1]=/opt/jboss2
+# JBOSS_USER[1]=jboss2
+# SERVER_NAME[1]=default
+# JBOSS_START[1]=1
+## No Console logging
+# JBOSS_CONSOLE[1]=/dev/null
+#
##################################################################
+#
+# This script will start as many instances of JBoss as there are
+# consecutive array entries for the variables defined below.
+#
+# There may be a unique jboss server instance for each $JBOSS_HOME[i]
+# and $SERVER_NAME[i] combination.
+#
# The following variables should be defined in /etc/rc.config.d/jboss.
# If they are not, the variables are defaulted below:
#
-# INSTANCE - server instance name. Normally "all", "default", or
-# "minimal". Maps to server instance at $JBOSS_HOME/server/$INSTANCE
+# JBOSS_HOME[i] - root directory for jboss installation, like
+# /opt/jboss-<version>.
+# The default for the 1st instance is /opt/jboss: JBOSS_HOME[0]=/opt/jboss.
+# No default for any other instance.
#
-# JBOSS_CONSOLE - file where jboss console logging will be written
-# Use "/dev/null" if console logging is not desired.
+# SERVER_NAME[i] - server instance name. Normally "all", "default", or
+# "minimal". Maps to server instance at $JBOSS_HOME/server/$SERVER_NAME
+# The default value is "default".
#
-# JBOSS_START - set to "0" to force JBOSS to not start when this script
+# JBOSS_START[i] - set to "0" to force JBOSS to not start when this script
# is run. Usefull when this script is run automatically at system
# startup time. Default is "1" to startup.
#
-# JBOSS_USER - it is username by which the jboss application server
+# JBOSS_USER[i] - it is username by which the jboss application server
# is started. The default user is jboss.
-
+#
+# JBOSS_CONSOLE[i] - file where jboss console logging will be written
+# Use "/dev/null" if console logging is not desired.
+# default is /var/opt/jboss/jboss_<user>_<instance>.log
+#
+# JAVA_HOME should also be defined in the target users environment, such
+# as is the case when it is exported from ~/.profile.
+#
+# NOTE: The notation for array subscript [0] is optional. You can refer to
+# JBOSS_HOME[0] as JBOSS_HOME.
+#
# read config variables from files in /etc/rc.config.d
-# by convention the config values should be in /etc/rc.config
-# if this file is not present, we will attempt to deal with it be
+# by convention the config values should be in a file /etc/rc.config.d,
+# such as /etc/rc.config.d/jboss. If these variables are not defined
+# in a configuration file in rc.config.d, we will attempt to deal with it by
# setting defaults in the program
if [ -f /etc/rc.config ]
then
- . /etc/rc.config
+ . /etc/rc.config
else
- print -u2 "ERROR: /etc/rc.config default file MISSING"
-
+ print "ERROR: /etc/rc.config default file MISSING" 1>&2
fi
+umask 022
-INSTANCE=${INSTANCE:-"all"}
-JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/var/opt/jboss/jboss_${INSTANCE}.log"}
+#
+# Make sure variables are defined at least for the first instance of the
+# array. Note that $SERVER_NAME is the same as ${SERVER_NAME[0]}
+
JBOSS_HOME=${JBOSS_HOME:-"/opt/jboss"}
-JBOSS_USER=${JBOSS_USER:-"jboss"}
-PATH=/sbin:/usr/sbin:/usr/bin
+
+PATH=/sbin:/usr/sbin:/usr/bin:$PATH
export PATH
-if [ ! -d ${JBOSS_CONSOLE%/*} ]
-then
- mkdir -p ${JBOSS_CONSOLE%/*}
- chmod 0755 ${JBOSS_CONSOLE%/*}
- chown $JBOSS_USER ${JBOSS_CONSOLE%/*}
-fi
+#Usage: isJBossRunning <jbossHome> <jbossUserId> <instance>
+# sets non zero return code if Jboss is not running
+# sets global isJBossRunningPid with 1st process id if it is running
+isJBossRunning()
+{
+ typeset JBossHome=$2 JBossUserId=$1 instance=$3 junk
+ ((isJBossRunningPid=0))
+ # pipeline reads 1st jboss pid if it is running for user, jboss home, and instance
+ ps -xu $JBossUserId |
+ grep "$JBossHome.*org.jboss.Main.*\-c[ \t]*$instance" | grep -v "grep" |
+ read isJBossRunningPid junk
+}
+# Usage: startJBoss <index>
+startJBoss()
+{
+ typeset -i i=$1
-#define the scripts to use to start and stop jboss
-CMD_START="export JAVA_HOME=$JAVA_HOME;$JBOSS_HOME/bin/run.sh -c $INSTANCE"
-CMD_STOP="export JAVA_HOME=$JAVA_HOME;$JBOSS_HOME/bin/shutdown.sh --shutdown"
+ (( ${JBOSS_START[i]} != 1 )) && return 0
-# Always run Jboss as user $JBOSS_USER
-SUBIT="su - $JBOSS_USER -c"
+ if [[ ! -d ${JBOSS_CONSOLE[i]%/*} ]]; then
+ mkdir -p ${JBOSS_CONSOLE[i]%/*}
+ chmod 0755 ${JBOSS_CONSOLE[i]%/*}
+ chown ${JBOSS_USER[i]} ${JBOSS_CONSOLE[i]%/*}
+ fi
-if [ ! -d "$JBOSS_HOME" ]; then
- print -u2 "ERROR: JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME"
- exit 1
-fi
+ if [[ ! -d ${JBOSS_HOME[i]} ]]; then
+ echo "ERROR: JBOSS_HOME[i] is not a valid directory : ${JBOSS_HOME[i]}" 1>&2
+ return 1
+ fi
-ps -eax|grep "org\.jboss\.Main"|grep -v "grep" 2>/dev/null 1>/dev/null
-NOT_RUNNING=$?
+ isJBossRunning ${JBOSS_USER[i]} ${JBOSS_HOME[i]} ${SERVER_NAME[i]}
+ if (( $? == 0 )); then
+ echo "JBoss AS is already running for user ${JBOSS_USER[i]} at ${JBOSS_HOME[i]} with instance ${SERVER_NAME[i]}" 1>&2
+ return 1
+ fi
+ # keeps last version of the console log around
+ [[ -f ${JBOSS_CONSOLE[i]} ]] && mv ${JBOSS_CONSOLE[i]} ${JBOSS_CONSOLE[i]}.old
+
+ # JBoss is not running, start it up
+ CMD_START="${JBOSS_HOME[i]}/bin/run.sh -c ${SERVER_NAME[i]}"
+ nohup su - ${JBOSS_USER[i]} -c "$CMD_START" >${JBOSS_CONSOLE[i]} 2>&1 &
+ echo "Starting JBoss AS for user ${JBOSS_USER[i]} at ${JBOSS_HOME[i]} with instance ${SERVER_NAME[i]}"
+}
+
+# Usage: stopJBoss <index>
+stopJBoss()
+{
+ typeset -i i=$1
+
+ # return silently if JBoss AS is not running
+ isJBossRunning ${JBOSS_USER[i]} ${JBOSS_HOME[i]} ${SERVER_NAME[i]} || return 0
+
+ # JBoss is running and $isJBossRunningPid is set to the process id
+ # SIGTERM does a gracefull shutdown like ^C
+ echo "Stopping JBoss AS PID $isJBossRunningPid for user ${JBOSS_USER[i]} at ${JBOSS_HOME[i]} with instance ${SERVER_NAME[i]}"
+ kill -s SIGTERM $isJBossRunningPid
+}
+
+stopWaitJBoss()
+{
+ typeset -i i=$1
+ stopJBoss $*
+ # wait for up to 30 seconds for the process to terminate gracefully
+ isJBossRunning ${JBOSS_USER[i]} ${JBOSS_HOME[i]} ${SERVER_NAME[i]} && printf "please wait " && sleep 10 &&
+ isJBossRunning ${JBOSS_USER[i]} ${JBOSS_HOME[i]} ${SERVER_NAME[i]} && printf "." && sleep 10 &&
+ isJBossRunning ${JBOSS_USER[i]} ${JBOSS_HOME[i]} ${SERVER_NAME[i]} && printf "." && sleep 10 &&
+ isJBossRunning ${JBOSS_USER[i]} ${JBOSS_HOME[i]} ${SERVER_NAME[i]} &&
+ echo "NOT Terminated! Wait a moment then check to see if the process has shut down gracefully, or terminate it now with\n \"kill -s SIGKILL $isJBossRunningPid\"" >&2
+}
+
+# Usage: doAll <command> <command args>
+doAll()
+{
+ typeset cmd=$1
+ typeset -i rc=0
+ shift
+
+ # loop thru the configuration file for servers to start or stop as identified by JBOSS_HOME[i] and the
+ # other parameters
+
+ ((i=0))
+ while [[ ${JBOSS_HOME[i]} != "" ]]
+ do
+
+ # set defaults for any missing values
+ SERVER_NAME[$i]=${SERVER_NAME[i]:-"default"}
+ JBOSS_USER[$i]=${JBOSS_USER[i]:-"jboss"}
+ JBOSS_CONSOLE[$i]=${JBOSS_CONSOLE[i]:-/var/opt/jboss/${JBOSS_USER[i]}/jboss_${SERVER_NAME[i]}.log}
+ JBOSS_START[$i]=${JBOSS_START[i]:-1}
+
+ $cmd $i $*
+ (($? != 0)) && rc=$?
+ ((i=i+1))
+ done
+ return $rc
+}
+
case "$1" in
-start_msg)
- echo "Starting JBoss if needed"
- ;;
-start)
- [ "$JBOSS_START" -ne "1" ] && exit 0
- if [ $NOT_RUNNING -eq 1 ]
- then
- nohup sh "$SUBIT \"$CMD_START\" >${JBOSS_CONSOLE} 2>&1 &" >/dev/null
- sleep 5
- ps -eax|grep "org\.jboss\.Main"|grep -v "grep" 2>/dev/null 1>/dev/null
- if [ $? -eq 0 ]
- then
- echo "JBoss Server Started"
- rval=0
- else
- print -u2 "ERROR :Unable to Start JBoss Server"
- print -u2 " See ${JBOSS_CONSOLE} for details"
- rval=1
- fi
- else
- print -u2 "ERROR: Another Instance of JBoss is running"
- rval=2
- fi
- ;;
-stop_msg)
- echo "Stopping JBoss"
- ;;
-stop)
- nohup sh "$SUBIT \"$CMD_STOP\" >>${JBOSS_CONSOLE} 2>&1" >/dev/null
- sleep 10
- ps -eax|grep "org\.jboss\.Main"|grep -v "grep" 2>/dev/null 1>/dev/null
- if [ $? -eq 0 ]
- then
- ps -eax|grep "org\.jboss\.Main"|grep -v "grep"|awk '{print $1}'|xargs kill -9 2>/dev/null 1>/dev/null
- if [ $? -eq 0 ]
- then
- sleep 5
- echo "JBoss Server Stopped"
- rval=0
- else
- print -u2 "ERROR: Unable to Stop JBoss Server"
- rval=1
- fi
- else
- echo "JBoss Server Stopped"
- rval=0
- fi
- ;;
-
-restart)
- $0 stop
- $0 start
- ;;
-*)
- echo "usage: $0 (start|stop|restart|help)"
+ start_msg)
+ echo "Starting JBoss"
+ ;;
+ start)
+ doAll startJBoss
+ ;;
+ stop_msg)
+ echo "Stopping JBoss"
+ ;;
+ stop)
+ doAll stopJBoss
+ ;;
+ stopwait)
+ doAll stopWaitJBoss
+ ;;
+ restart)
+ $0 stopwait
+ $0 start
+ ;;
+ *)
+ echo "usage: $0 (start|stop|restart|help)" 1>&2
+ exit 1
esac
-exit $rval
+exit $?
More information about the jboss-cvs-commits
mailing list