我的Blog我做主^_^

走向一条通往JAVA的不归路...

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  64 随笔 :: 68 文章 :: 77 评论 :: 0 Trackbacks

  今天上午碰到这样一个问,就是在向catalina.sh里添加信息<CATALINA_OPTS="-Dcom.onewaveinc.WebPro=/home/jakarta-tomcat-4.1.30/webapps/ROOT/webpro.xml">时,再重新启动Tomcat就会报bin/startup.sh文件找不到的错误,利用bin/catalina.sh start命令也不行,经过询问朋友才最终明白是什么原因.
解决:
原来我是把linux服务器上的catalina.sh文件下载到本地后做修改,然后再传到服务器上,这时候上传的文件没有执行权限,所以出现了那种错误,这时需要用chmod修改文件的执行权限,或者直接在服务器上修改就可以了.

感悟:知道的还是太少了,学吧,呵呵,你就学吧......

附:
chmod命令详解

指令名称 : chmod
使用权限 : 所有使用者
使用方式 : chmod [-cfvR] [--help] [--version] mode file...
说明 : Linux/Unix 的档案调用权限分为三级 : 档案拥有者、群组、其他。利用 chmod 可以藉以控制档案如何被他人所调用。
参数 :
mode : 权限设定字串,格式如下 : [ugoa...][[+-=][rwxX]...][,...],其中
u 表示该档案的拥有者,g 表示与该档案的拥有者属于同一个群体(group)者,o 表示其他以外的人,a 表示这三者皆是。
+ 表示增加权限、- 表示取消权限、= 表示唯一设定权限。
r 表示可读取,w 表示可写入,x 表示可执行,X 表示只有当该档案是个子目录或者该档案已经被设定过为可执行。
-c : 若该档案权限确实已经更改,才显示其更改动作
-f : 若该档案权限无法被更改也不要显示错误讯息
-v : 显示权限变更的详细资料
-R : 对目前目录下的所有档案与子目录进行相同的权限变更(即以递回的方式逐个变更)
--help : 显示辅助说明
--version : 显示版本
范例 :将档案 file1.txt 设为所有人皆可读取 :
chmod ugo+r file1.txt 
将档案 file1.txt 设为所有人皆可读取 :
chmod a+r file1.txt 
将档案 file1.txt 与 file2.txt 设为该档案拥有者,与其所属同一个群体者可写入,但其他以外的人则不可写入 :
chmod ug+w,o-w file1.txt file2.txt 
将 ex1.py 设定为只有该档案拥有者可以执行 :
chmod u+x ex1.py 
将目前目录下的所有档案与子目录皆设为任何人可读取 :
chmod -R a+r * 
此外chmod也可以用数字来表示权限如 chmod 777 file
语法为:chmod abc file
其中a,b,c各为一个数字,分别表示User、Group、及Other的权限。
r=4,w=2,x=1
若要rwx属性则4+2+1=7;
若要rw-属性则4+2=6;
若要r-x属性则4+1=7。
范例:
chmod a=rwx file 

chmod 777 file 
效果相同
chmod ug=rwx,o=x file 

chmod 771 file 
效果相同
若用chmod 4755 filename可使此程序具有root的权限

catalina.sh详解:

1 - 概述

脚本catalina.sh用于启动和关闭tomcat服务器,是最关键的脚本
另外的脚本startup.sh和shutdown.sh都是使用不同的参数调用了该脚本
该脚本的使用方法如下(引自该脚本本身):

  echo "Usage: catalina.sh ( commands ... )"
  echo "commands:"
  echo "  debug             Start Catalina in a debugger"
  echo "  debug -security   Debug Catalina with a security manager"
  echo "  embedded          Start Catalina in embedded mode"
  echo "  jpda start        Start Catalina under JPDA debugger"
  echo "  run               Start Catalina in the current window"
  echo "  run -security     Start in the current window with security manager"
  echo "  start             Start Catalina in a separate window"
  echo "  start -security   Start in a separate window with security manager"
  echo "  stop              Stop Catalina"

2 - 脚本分析

#!/bin/sh


# =============================================================
# 该脚本设置正确的环境变量和系统信息,然后启动或者停止tomcat server
# 具体的操作是:
# 使用命令行参数作为args的实参,调用org.apache.catalina.startup.Bootstrap.main(String[])
# ==============================================================

# -----------------------------------------------------------------------------
# Start/Stop Script for the CATALINA Server
#
# Environment Variable Prequisites
#
#   CATALINA_HOME   May point at your Catalina "build" directory.
#
#   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
#                   of a Catalina installation.  If not present, resolves to
#                   the same directory that CATALINA_HOME points to.
#
#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
#                   "stop", or "run" command is executed.
#
#   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
#                   the JVM should use (java.io.tmpdir).  Defaults to
#                   $CATALINA_BASE/temp.
#
#   JAVA_HOME       Must point at your Java Development Kit installation.
#
#   JAVA_OPTS       (Optional) Java runtime options used when the "start",
#                   "stop", or "run" command is executed.
#
#   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
#                   command is executed. The default is "dt_socket".
#
#   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
#                   command is executed. The default is 8000.
#
#   JSSE_HOME       (Optional) May point at your Java Secure Sockets Extension
#                   (JSSE) installation, whose JAR files will be added to the
#                   system class path used to start Tomcat.
#
#   CATALINA_PID    (Optional) Path of the file which should contains the pid
#                   of catalina startup java process, when start (fork) is used
# -----------------------------------------------------------------------------

# OS specific support.  $var _must_ be set to either true or false.

cygwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
esac


# PRG是被执行的脚本的名称,可以认为PRG=="catalina.sh",也可能是某个符号链,指向该脚本。

PRG="$0"


# 处理了一下PRG,等循环跳出之后PRG成为 ????

while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '.*/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done



# PRGDIR是PRG的目录路径名称

PRGDIR=`dirname "$PRG"`


# 执行$CATALINA_HOME/BIN/setenv.sh来设置环境变量
# [ -r filename ] 是判断是否文件存在且可读

CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
  . "$CATALINA_HOME"/bin/setenv.sh
fi



# For Cygwin, 确保所有的路径名都符合UNIX格式

if $cygwin; then
  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  [ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`
  [ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"`
  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  [ -n "$JSSE_HOME" ] && JSSE_HOME=`cygpath --path --unix "$JSSE_HOME"`
fi


# 设置用来初始化SystemClassLoader的CLASSPATH变量:通过执行脚本setclasspath.sh完成
# 注意:脚本setclasspath.sh改变了原来的$CLASSPATH变量,而把它设为:
# CLASSPATH=$CATALINA_HOME/bin/bootstrap.jar:$JAVA_HOME/lib/tools.jar
# 其中bootstrap.jar是package org.apache.catalina.startup的打包文件,
# 含有启动方法org.apache.catalina.startup.Bootstrap.main(String[] args)
# tools.jar含有javac编译器,用来把jsp文件编译成为servlet class

if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
  BASEDIR="$CATALINA_HOME"
  . "$CATALINA_HOME"/bin/setclasspath.sh
else
  echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
  echo "This file is needed to run this program"
  exit 1
fi


# 在CLASSPATH环境变量后面补上一些JAR文件
# [ -n string ] 判断字符串是否长度非0;[ -z string ] 判断字符串是否长度为0
# 它们可以用来判断是否某个环境变量已经被设置

if [ -n "$JSSE_HOME" ]; then
  CLASSPATH="$CLASSPATH":"$JSSE_HOME"/lib/jcert.jar:"$JSSE_HOME"/lib/jnet.jar:"$JSSE_HOME"/lib/jsse.jar
fi
CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/bootstrap.jar



# 指定CATALINA_BASE变量
# 如果CATALINA_BASE没有值,就让CATALINA_BASE=$CATALINA_HOME


if [ -z "$CATALINA_BASE" ] ; then
  CATALINA_BASE="$CATALINA_HOME"
fi



# 指定CATALINA_TMPDIR变量
# 如果CATALINA_TMPDIR没有值,就让CATALINA_TMPDIR=$CATALINA_BASE/temp

if [ -z "$CATALINA_TMPDIR" ] ; then
  # Define the java.io.tmpdir to use for Catalina
  CATALINA_TMPDIR="$CATALINA_BASE"/temp
fi


# For Cygwin, 在执行java程序前把路径名转换成WINDOWS格式

if $cygwin; then
  JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  CATALINA_HOME=`cygpath --path --windows "$CATALINA_HOME"`
  CATALINA_BASE=`cygpath --path --windows "$CATALINA_BASE"`
  CATALINA_TMPDIR=`cygpath --path --windows "$CATALINA_TMPDIR"`
  CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  JSSE_HOME=`cygpath --path --windows "$JSSE_HOME"`
fi



# 显示信息,然后执行命令
echo "Using CATALINA_BASE:   $CATALINA_BASE"
echo "Using CATALINA_HOME:   $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
echo "Using JAVA_HOME:       $JAVA_HOME"

# ......当执行catalina.sh的参数是jpda的时候......

if [ "$1" = "jpda" ] ; then
  if [ -z "$JPDA_TRANSPORT" ]; then
    JPDA_TRANSPORT="dt_socket"
  fi
  if [ -z "$JPDA_ADDRESS" ]; then
    JPDA_ADDRESS="8000"
  fi
  if [ -z "$JPDA_OPTS" ]; then
    JPDA_OPTS="-Xdebug -Xrunjdwp:transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=n"
  fi
  CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
  shift
fi



# ......当执行catalina.sh的参数是debug的时候......

if [ "$1" = "debug" ] ; then
  shift
  if [ "$1" = "-security" ] ; then
    echo "Using Security Manager"
    shift
    exec "$_RUNJDB" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -sourcepath "$CATALINA_HOME"/../../jakarta-tomcat-4.0/catalina/src/share \
      -Djava.security.manager \
      -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
  else
    exec "$_RUNJDB" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -sourcepath "$CATALINA_HOME"/../../jakarta-tomcat-4.0/catalina/src/share \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
  fi



# ......当执行catalina.sh的参数是embedded的时候......

elif [ "$1" = "embedded" ] ; then
  shift
  echo "Embedded Classpath: $CLASSPATH"
  exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
    -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
    -Dcatalina.base="$CATALINA_BASE" \
    -Dcatalina.home="$CATALINA_HOME" \
    -Djava.io.tmpdir="$CATALINA_TMPDIR" \
    org.apache.catalina.startup.Embedded "$@"



# +----------------------------------------------------+
# |  ......当执行catalina.sh的参数是run的时候......    |
# |  在当前窗口中启动tomcat服务器!!!                |
# +----------------------------------------------------+

elif [ "$1" = "run" ]; then

  # 把参数run去掉

  shift
  

  # 如果参数是run -security,则启动Security Manager

  if [ "$1" = "-security" ] ; then
    echo "Using Security Manager"
    shift
    exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Djava.security.manager \
      -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
      

  # 如果参数是孤单的run,则在本窗口中启动tomcat服务器
  # 在本窗口中启动的方法是使用exec,让当前进程fork一个新进程来启动tomcat,当前进程是tomcat的父进程
  # 启动tomcat的类是org.apache.catalina.startup.Bootstrap.main("start");

  else
    exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start
  fi


# +----------------------------------------------------+
# |  ......当执行catalina.sh的参数是start的时候......  |
# |  在新窗口中启动tomcat服务器!!!                  |
# +----------------------------------------------------+

elif [ "$1" = "start" ] ; then

  # 把参数start去掉

  shift
  
  # 创建一个文件(如果文件不存在的话)$CATALINA_BASE/logs/catalina.out  

  touch "$CATALINA_BASE"/logs/catalina.out

  # 如果参数是start -security,则启动Security Manager

  if [ "$1" = "-security" ] ; then
    echo "Using Security Manager"
    shift
    "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Djava.security.manager \
      -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start \
      >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &

      if [ ! -z "$CATALINA_PID" ]; then
        echo $! > $CATALINA_PID
      fi
      

  # 如果参数是孤单的start,那么在新窗口中启动tomcat

  else
    "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start \
      >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &

      if [ ! -z "$CATALINA_PID" ]; then
        echo $! > $CATALINA_PID
      fi      
  fi


# +----------------------------------------------------+
# |  ......当执行catalina.sh的参数是stop的时候......   |
# |  关闭tomcat服务器!!!                            |
# +----------------------------------------------------+

elif [ "$1" = "stop" ] ; then

  # 把参数stop去掉

  shift
  

  # 关闭tomcat服务器的类是org.apache.catalina.startup.Bootstrap->main("stop");
  # 注意:java -D 是设置系统属性
  
  exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
    -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
    -Dcatalina.base="$CATALINA_BASE" \
    -Dcatalina.home="$CATALINA_HOME" \
    -Djava.io.tmpdir="$CATALINA_TMPDIR" \
    org.apache.catalina.startup.Bootstrap "$@" stop



# +----------------------------------------------------+
# |  ......当执行catalina.sh的参数不可辨认的时候...... |
# |  打印帮助信息,由此查看各种参数代表的意义!!!    |
# +----------------------------------------------------+

else
  echo "Usage: catalina.sh ( commands ... )"
  echo "commands:"
  echo "  debug             Start Catalina in a debugger"
  echo "  debug -security   Debug Catalina with a security manager"
  echo "  embedded          Start Catalina in embedded mode"
  echo "  jpda start        Start Catalina under JPDA debugger"
  echo "  run               Start Catalina in the current window"
  echo "  run -security     Start in the current window with security manager"
  echo "  start             Start Catalina in a separate window"
  echo "  start -security   Start in a separate window with security manager"
  echo "  stop              Stop Catalina"
  exit 1

fi



posted on 2007-01-30 13:43 java_蝈蝈 阅读(8566) 评论(0)  编辑  收藏 所属分类: LINUX

只有注册用户登录后才能发表评论。


网站导航: