今天上班发现tomcat6无法启动。尝试使用以下命令停止和启动时:
service tomcat6 stop ; > /var/log/tomcat6/catalina.out && service tomcat6 start && less +F /var/log/tomcat6/catalina.out
它报告OK
启动 tomcat,但使用ps
,没有显示 tomcat 进程。catalina.out 文件也没有显示任何内容,完全空白。在查看 /var/log/tomcat6/tomcat6-initd.log 时,我看到两行在每次尝试时一遍又一遍地重复:
/usr/sbin/tomcat6: line 60: ${2}: ambiguous redirect
/usr/sbin/tomcat6: line 30: ${2}: ambiguous redirect
查看 /usr/sbin/tomcat6,两行内容如下:
${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
-Djava.util.logging.config.file="${CATALINA_BASE}/conf/logging.properties" \
-Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" \
org.apache.catalina.startup.Bootstrap start \
>> ${2} 2>&1 &
60 和 30 的第一行相同。我的$JAVA_OPTS
阅读:
JAVA_OPTS="-server -Xss128K -Xms3G -Xmx3G -XX:MaxPermSize=256M -Dambiguous.url=https://ambiguous.url.com"
据我所知(老实说,不确定在哪里看)$CATALINA_OPTS
是空的,但我可能会弄错。可以肯定的是,我没有调整它的值,并且确信该值与歧义重定向问题无关。
更新:通过将我们的 tomcat6 包更新到最新版本,我现在没有收到上面看到的错误。事实上,/usr/sbin/tomcat6 文件在它之前指向我的区域周围读取完全不同:
${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
-classpath "$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
-Djava.util.logging.config.file="${CATALINA_BASE}/conf/logging.properties" \
-Djava.util.logging.manager="org.apache.juli.ClassLoaderLogManager" \
org.apache.catalina.startup.Bootstrap start \
>> ${CATALINA_BASE}/logs/catalina.out 2>&1 &
if [ ! -z "$CATALINA_PID" ]; then
echo $! > $CATALINA_PID
fi
现在它变得更加复杂,因为 tomcat6-initd.log 根本没有报告任何内容,但服务仍然没有启动。运行带有 a 的 init 脚本-x
会在启动时产生以下输出:
# service tomcat6 start
+ '[' -r /lib/lsb/init-functions ']'
+ . /lib/lsb/init-functions
++ lsb_release -i -s
+ DISTRIB_ID=Scientific
++ basename /etc/init.d/tomcat6
+ NAME=tomcat6
+ unset ISBOOT
+ '[' t = S -o t = K ']'
+ '[' -x /sbin/runuser ']'
+ SU='/sbin/runuser -s /bin/sh'
+ TOMCAT_CFG=/etc/tomcat6/tomcat6.conf
+ '[' -r /etc/tomcat6/tomcat6.conf ']'
+ . /etc/tomcat6/tomcat6.conf
++ CATALINA_BASE=/usr/share/tomcat6
++ CATALINA_HOME=/usr/share/tomcat6
++ JASPER_HOME=/usr/share/tomcat6
++ CATALINA_TMPDIR=/var/cache/tomcat6/temp
++ JAVA_OPTS='-Xms3072m -Xmx3072m -Xss512m -XX:MaxPermSize=512m -server -Dambiguous.url=https://ambiguous.url.com'
++ TOMCAT_USER=root
++ SECURITY_MANAGER=false
++ SHUTDOWN_WAIT=30
++ SHUTDOWN_VERBOSE=false
++ CATALINA_PID=/var/run/tomcat6.pid
+ '[' -r /etc/sysconfig/tomcat6 ']'
+ . /etc/sysconfig/tomcat6
+ CONNECTOR_PORT=8080
+ TOMCAT_SCRIPT=/usr/sbin/tomcat6
+ TOMCAT_PROG=tomcat6
+ TOMCAT_USER=root
+ TOMCAT_LOG=/var/log/tomcat6/tomcat6-initd.log
+ RETVAL=0
+ RETVAL=0
+ case "$1" in
+ start
+ echo -n 'Starting tomcat6: '
Starting tomcat6: + '[' 0 '!=' 0 ']'
+ '[' -f /var/lock/subsys/tomcat6 ']'
+ '[' -f /var/run/tomcat6.pid ']'
+ read kpid
+ '[' -d /proc/ ']'
+ log_success_msg
+ /etc/redhat-lsb/lsb_log_message success
[ OK ]
+ '[' Scientific = MandrivaLinux ']'
+ RETVAL=0
+ return
+ exit 0
如果我要在运行 tomcat 的单独服务器上运行完全相同的设置(有多个虚拟机作为集群运行),输出为:
# service tomcat6 start
+ '[' -r /lib/lsb/init-functions ']'
+ . /lib/lsb/init-functions
++ lsb_release -i -s
+ DISTRIB_ID=Scientific
++ basename /etc/init.d/tomcat6
+ NAME=tomcat6
+ unset ISBOOT
+ '[' t = S -o t = K ']'
+ '[' -x /sbin/runuser ']'
+ SU='/sbin/runuser -s /bin/sh'
+ TOMCAT_CFG=/etc/tomcat6/tomcat6.conf
+ '[' -r /etc/tomcat6/tomcat6.conf ']'
+ . /etc/tomcat6/tomcat6.conf
++ CATALINA_BASE=/usr/share/tomcat6
++ CATALINA_HOME=/usr/share/tomcat6
++ JASPER_HOME=/usr/share/tomcat6
++ CATALINA_TMPDIR=/var/cache/tomcat6/temp
++ JAVA_OPTS='-Xms3072m -Xmx3072m -Xss512m -XX:MaxPermSize=512m -server -Dambiguous.url=https://ambiguous.url.com'
++ TOMCAT_USER=root
++ SECURITY_MANAGER=false
++ SHUTDOWN_WAIT=30
++ SHUTDOWN_VERBOSE=false
++ CATALINA_PID=/var/run/tomcat6.pid
+ '[' -r /etc/sysconfig/tomcat6 ']'
+ . /etc/sysconfig/tomcat6
+ CONNECTOR_PORT=8080
+ TOMCAT_SCRIPT=/usr/sbin/tomcat6
+ TOMCAT_PROG=tomcat6
+ TOMCAT_USER=root
+ TOMCAT_LOG=/var/log/tomcat6/tomcat6-initd.log
+ RETVAL=0
+ RETVAL=0
+ case "$1" in
+ start
+ echo -n 'Starting tomcat6: '
Starting tomcat6:
+ '[' 0 '!=' 0 ']'
+ '[' -f /var/lock/subsys/tomcat6 ']'
+ export CATALINA_PID=/var/run/tomcat6.pid
+ CATALINA_PID=/var/run/tomcat6.pid
+ touch /var/run/tomcat6.pid
+ '[' 0 -eq 0 -a 0 -eq 0 ']'
+ chown root:root /var/run/tomcat6.pid
+ '[' 0 -eq 0 ']'
+ touch /var/log/tomcat6/tomcat6-initd.log
+ '[' 0 -eq 0 -a 0 -eq 0 ']'
+ chown root:root /var/log/tomcat6/tomcat6-initd.log
+ parseOptions
+ options=
++ awk '!/^#/ && !/^$/ { ORS=" "; print "export ", $0, ";" }' /etc/tomcat6/tomcat6.conf
+ options=' export CATALINA_BASE="/usr/share/tomcat6" ; export CATALINA_HOME="/usr/share/tomcat6" ; export JASPER_HOME="/usr/share/tomcat6" ; export CATALINA_TMPDIR="/var/cache/tomcat6/temp" ; export JAVA_OPTS="-Xms3072m -Xmx3072m -Xss512m -XX:MaxPermSize=512m -server -Dambiguous.url=https://ambiguous.url.com" ; export TOMCAT_USER="root" ; export SECURITY_MANAGER="false" ; export SHUTDOWN_WAIT="30" ; export SHUTDOWN_VERBOSE="false" ; export CATALINA_PID="/var/run/tomcat6.pid" ; '
+ '[' -r /etc/sysconfig/tomcat6 ']'
++ awk '!/^#/ && !/^$/ { ORS=" ";
print "export ", $0, ";" }' /etc/sysconfig/tomcat6
+ options=' export CATALINA_BASE="/usr/share/tomcat6" ; export CATALINA_HOME="/usr/share/tomcat6" ; export JASPER_HOME="/usr/share/tomcat6" ; export CATALINA_TMPDIR="/var/cache/tomcat6/temp" ; export JAVA_OPTS="-Xms3072m -Xmx3072m -Xss512m -XX:MaxPermSize=512m -server -Dambiguous.url=https://ambiguous.url.com" ; export TOMCAT_USER="root" ; export SECURITY_MANAGER="false" ; export SHUTDOWN_WAIT="30" ; export SHUTDOWN_VERBOSE="false" ; export CATALINA_PID="/var/run/tomcat6.pid" ; '
+ TOMCAT_SCRIPT=' export CATALINA_BASE="/usr/share/tomcat6" ; export CATALINA_HOME="/usr/share/tomcat6" ; export JASPER_HOME="/usr/share/tomcat6" ; export CATALINA_TMPDIR="/var/cache/tomcat6/temp" ; export JAVA_OPTS="-Xms3072m -Xmx3072m -Xss512m -XX:MaxPermSize=512m -server -Dambiguous.url=https://ambiguous.url.com" ; export TOMCAT_USER="root" ; export SECURITY_MANAGER="false" ; export SHUTDOWN_WAIT="30" ; export SHUTDOWN_VERBOSE="false" ; export CATALINA_PID="/var/run/tomcat6.pid" ; /usr/sbin/tomcat6'
+ '[' 0 -eq 0 -a false = true ']'
+ '[' 0 -eq 0 ']'
+ /sbin/runuser -s /bin/sh - root -c ' export CATALINA_BASE="/usr/share/tomcat6" ; export CATALINA_HOME="/usr/share/tomcat6" ; export JASPER_HOME="/usr/share/tomcat6" ; export CATALINA_TMPDIR="/var/cache/tomcat6/temp" ; export JAVA_OPTS="-Xms3072m -Xmx3072m -Xss512m -XX:MaxPermSize=512m -server -Dambiguous.url=https://ambiguous.url.com" ; export TOMCAT_USER="root" ; export SECURITY_MANAGER="false" ; export SHUTDOWN_WAIT="30" ; export SHUTDOWN_VERBOSE="false" ; export CATALINA_PID="/var/run/tomcat6.pid" ; /usr/sbin/tomcat6 start'
+ '[' 0 -eq 0 ']'
+ log_success_msg
+ /etc/redhat-lsb/lsb_log_message success
[ OK ]
+ touch /var/lock/subsys/tomcat6
+ '[' Scientific = MandrivaLinux ']'
+ exit 0
为了彻底起见,start()
函数中的/etc/init.d/tomcat6
内容如下:
function start() {
echo -n "Starting ${TOMCAT_PROG}: "
if [ "$RETVAL" != "0" ]; then
log_failure_msg
return
fi
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
if [ -d "/proc/${kpid}" ]; then
log_success_msg
if [ "$DISTRIB_ID" = "MandrivaLinux" ]; then
echo
fi
RETVAL="0"
return
fi
fi
fi
# fix permissions on the log and pid files
export CATALINA_PID="/var/run/${NAME}.pid"
touch $CATALINA_PID 2>&1 || RETVAL="4"
if [ "$RETVAL" -eq "0" -a "$?" -eq "0" ]; then
chown ${TOMCAT_USER}:${TOMCAT_USER} $CATALINA_PID
fi
[ "$RETVAL" -eq "0" ] && touch $TOMCAT_LOG 2>&1 || RETVAL="4"
if [ "$RETVAL" -eq "0" -a "$?" -eq "0" ]; then
chown ${TOMCAT_USER}:${TOMCAT_USER} $TOMCAT_LOG
fi
parseOptions
if [ "$RETVAL" -eq "0" -a "$SECURITY_MANAGER" = "true" ]; then
$SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start-security" \
>> ${TOMCAT_LOG} 2>&1 || RETVAL="4"
else
[ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4"
fi
if [ "$RETVAL" -eq "0" ]; then
log_success_msg
touch /var/lock/subsys/${NAME}
else
log_failure_msg "Error code ${RETVAL}"
fi
if [ "$DISTRIB_ID" = "MandrivaLinux" ]; then
echo
fi
}