current EnviornmentRHEL 5JDK 1.5.0Tomcat6Virtual Machine
Hello all,I am looking at our existing script we are trying to find out why our
script will not start Tomcat6. We have checked the following. We did change the
script and we will show you the one that works but is not as extensive.
Run level is 3 checked /etc/rc3.d for symbolic link, here is what is
listedS80tomcat6 -> ../init.d/tomcat6
Also checked /etc/rc.d/rc3.dS80tomcat6 -> ../init.d/tomcat6
Checked: /etc/init.d/tomcat6 Below is the script that is not starting the
service
#!/bin/bash#set -x
## tomcat6 This shell script takes care of starting and stopping Tomcat##
chkconfig: - 80 20#### BEGIN INIT INFO# Provides: tomcat6# Required-Start:
$network $syslog# Required-Stop: $network $syslog# Default-Start:#
Default-Stop:# Description: Release implementation for Servlet 2.4 and JSP 2.0#
Short-Description: start and stop tomcat### END INIT INFO## - originally
written by Henri Gomez, Keith Irwin, and Nicolas Mailhot# - heavily rewritten
by Deepak Bhole and Jason Corley#
# commented out until the RHEL and FC daemon functions converge# Source the
function library#if [ -r "/etc/rc.d/init.d/functions" ]; then #.
/etc/rc.d/init.d/functions#fi
NAME="$(basename $0)"unset ISBOOTif [ "${NAME:0:1}" = "S" -o "${NAME:0:1}" =
"K" ]; then NAME="${NAME:3}" ISBOOT="1"fi
# For SELinux we need to use 'runuser' not 'su'if [ -x "/sbin/runuser" ]; then
SU="/sbin/runuser"else SU="su"fi
# Get the tomcat config (use this for environment specific
settings)TOMCAT_CFG="/etc/tomcat6/tomcat6.conf"if [ -r "$TOMCAT_CFG" ]; then
. ${TOMCAT_CFG}fi
# Get instance specific config fileif [ -r "/etc/sysconfig/${NAME}" ]; then
. /etc/sysconfig/${NAME}fi
# Define which connector port to useCONNECTOR_PORT="${CONNECTOR_PORT:-8080}"
# Path to the tomcat launch
script#TOMCAT_SCRIPT="/usr/bin/dtomcat6"TOMCAT_SCRIPT="/usr/local/tomcat6/bin/catalina.sh"
# Path to the script that will refresh jar symlinks on
startup#$TOMCAT_RELINK_SCRIPT="${CATALINA_HOME}/bin/relink"
# Tomcat program nameTOMCAT_PROG="$NAME" # Define the tomcat
usernameTOMCAT_USER="${TOMCAT_USER:-tomcat}"
# Define the tomcat log
fileTOMCAT_LOG="${TOMCAT_LOG:-/var/log/tomcat6/catalina.out}"
RETVAL="0"
# remove when the RHEL and FC daemon functions converge# (pulled from
/etc/rc.d/init.d/functions)function checkpid() { local i for i in $* ; do
if [ -d "/proc/${i}" ]; then return 0 fi done
return 1}
# remove when the RHEL and FC daemon functions converge# (pulled from
/etc/rc.d/init.d/functions)function echo_failure() { echo -en "\\033[60G"
echo -n "[ " echo -n $"FAILED" echo -n " ]" echo -ne "\r" return
1}
# remove when the RHEL and FC daemon functions converge# (pulled from
/etc/rc.d/init.d/functions)function echo_success() { echo -en "\\033[60G"
echo -n "[ " echo -n $"OK" echo -n " ]" echo -ne "\r" return 0}
# Look for open ports, as the function name might implyfunction findFreePorts()
{ local isSet1="false" local isSet2="false" local isSet3="false"
local lower="8000" randomPort1="0" randomPort2="0" randomPort3="0"
local -a listeners="( $( netstat -ntl | \
awk '/^tcp/ {gsub("(.)*:", "", $4); print $4}' ) )"
while [ "$isSet1" = "false" ] || \ [ "$isSet2" = "false" ] || \
[ "$isSet3" = "false" ]; do let port="${lower}+${RANDOM:0:4}"
if [ -z `expr " ${listeners[*]} " : ".*\( $port \).*"` ]; then if [
"$isSet1" = "false" ]; then export randomPort1="$port"
isSet1="true" elif [ "$isSet2" = "false" ]; then
export randomPort2="$port" isSet2="true" elif [
"$isSet3" = "false" ]; then export randomPort3="$port"
isSet3="true" fi fi done}
function makeHomeDir() { if [ ! -d "$CATALINA_HOME" ]; then echo
"$CATALINA_HOME does not exist, creating" if [ ! -d "/var/lib/${NAME}"
]; then mkdir -p /var/lib/${NAME} cp -pLR
/var/lib/tomcat6/* /var/lib/${NAME} fi mkdir -p $CATALINA_HOME
${CATALINA_HOME}/conf /var/cache/${NAME}/temp \
/var/cache/${NAME}/work /var/log/${NAME} for i in temp work; do
ln -fs /var/cache/${NAME}/${i} ${CATALINA_HOME}/${i} done for i
in common server shared webapps; do ln -fs /var/lib/${NAME}/${i}
${CATALINA_HOME}/${i} done ln -fs /var/log/${NAME}
${CATALINA_HOME}/logs cp -pLR /etc/tomcat6/* ${CATALINA_HOME}/conf/
cp -pLR /usr/local/tomcat6/bin $CATALINA_HOME cp -pLR
/var/cache/tomcat6/work/* ${CATALINA_HOME}/work/ chown
${TOMCAT_USER}:${TOMCAT_USER} /var/log/${NAME} fi}
function parseOptions() { options="" options="$options $(
awk '!/^#/ && !/^$/ { ORS=" "; print "export ", $0, ";" }' \
$TOMCAT_CFG )" if [ -r "/etc/sysconfig/${NAME}" ]; then
options="$options $( awk '!/^#/ && !/^$/ { ORS=" ";
print "export ", $0, ";" }' \
/etc/sysconfig/${NAME} )" fi TOMCAT_SCRIPT="$options
$TOMCAT_SCRIPT"}
# See how we were called.function start() { echo -n "Starting
${TOMCAT_PROG}: " if [ -f "/var/lock/subsys/${NAME}" ] ; then if [ -f
"/var/run/${NAME}.pid" ]; then read kpid < /var/run/${NAME}.pid
if checkpid $kpid 2>&1; then echo "$NAME process
already running" return -1 else
echo "lock file found but no process running for"
echo "pid $kpid, continuing" fi fi fi
export CATALINA_PID="/var/run/${NAME}.pid" touch $CATALINA_PID chown
${TOMCAT_USER}:${TOMCAT_USER} $CATALINA_PID if [ "$CATALINA_HOME" !=
"/usr/local/tomcat6" ]; then # Create a tomcat directory if it doesn't
exist makeHomeDir # If CATALINA_HOME doesn't exist modify port
number so that # multiple instances don't interfere with each other
findFreePorts sed -i -e "s/8005/${randomPort1}/g" -e
"s/8080/${CONNECTOR_PORT}/g" \ -e "s/8009/${randomPort2}/g" -e
"s/8443/${randomPort3}/g" \ ${CATALINA_HOME}/conf/server.xml fi#
$TOMCAT_RELINK_SCRIPT $SU - $TOMCAT_USER -c "$TOMCAT_SCRIPT start" >>
$TOMCAT_LOG 2>&1 RETVAL="$?" if [ "$RETVAL" -eq 0 ]; then
echo_success touch /var/lock/subsys/${NAME} else echo_failure
fi echo return $RETVAL}
function status() { RETVAL="1" if [ -f "/var/run/${NAME}.pid" ]; then
read kpid < /var/run/${NAME}.pid if checkpid $kpid 2>&1; then
echo "$0 is already running (${kpid})" RETVAL="0" else
echo "lock file found but no process running for pid $kpid" fi
else pid="$(pgrep -u tomcat java)" if [ -n "$pid" ]; then
echo "$0 running (${pid}) but no PID file exists" RETVAL="0"
else echo "$0 is stopped" fi fi return $RETVAL}
function stop() { local STOP_VERBOSE="false" echo -n "Stopping
$TOMCAT_PROG: " if [ -f "/var/lock/subsys/${NAME}" ]; then $SU -
$TOMCAT_USER -c "$TOMCAT_SCRIPT stop" >> $TOMCAT_LOG 2>&1 RETVAL="$?"
if [ "$RETVAL" -eq "0" ]; then count="0" if [ -f
"/var/run/${NAME}.pid" ]; then read kpid < /var/run/${NAME}.pid
until [ "$(ps --pid $kpid | grep -c $kpid)" -eq "0" ] || \
[ "$count" -gt "$SHUTDOWN_WAIT" ]; do if [
"$STOP_VERBOSE" = "true" ]; then echo -n -e "\nwaiting
for processes $kpid to exit" fi sleep 1
let count="${count}+1" done if [
"$count" -gt "$SHUTDOWN_WAIT" ]; then if [ "$STOP_VERBOSE" =
"true" ]; then echo -n -e "\nkilling processes which
didn't stop" echo -n -e "after "
echo -n "$SHUTDOWN_WAIT seconds" fi kill
-9 $kpid fi echo_success if [
"$count" -gt "0" ]; then echo -n -e "\n" fi
fi rm -f /var/lock/subsys/$NAME /var/run/$NAME.pid
else echo_failure fi fi}
# See how we were called.case "$1" in start) parseOptions
start ;; stop) parseOptions stop ;; restart)
parseOptions stop sleep 2 start ;;
condrestart) if [ -f "/var/run/${NAME}.pid" ]; then
parseOptions stop start fi ;; status)
status ;; version) parseOptions
"${JAVA_HOME}/bin/java" \ -classpath
"${CATALINA_HOME}/server/lib/catalina.jar" \
org.apache.catalina.util.ServerInfo ;; *) echo "Usage:
$TOMCAT_PROG {start|stop|restart|condrestart|status|version}" exit 1esac
exit $RETVAL
****************************************************************************************************************************************************************************************************************************************this
is the script that will start the service under tomcat user but will not stop
the service.
case $1 in start) su root /usr/local/tomcat6/bin/startup.sh ;;stop) su root
/usr/local/tomcat6/bin/shutdown.sh ;;restart) su root
/usr/local/tomcat6/bin/shutdown.sh su root /usr/local/tomcat6/bin/startup.sh
;;esac exit 0
Thank you for any time you can offer to us.
_________________________________________________________________
Get more out of the Web. Learn 10 hidden secrets of Windows Live.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008