- #!/bin/bash
- #JDK 的安装目录通过参数传递给脚本,当脚本没有接收到 JDK 参数时,
- #查找Tomcat安装目录的父目录下是否有 jdk1.6.0_14 目录,
- #将管理服务的命令集成为一个脚本命令,传递给脚本的参数区分不同的请求命令。
- #=========================================================================================================
- #@author yuchao1@staff.sina.com.cn
- #@time 20101117 14:13:12
- #=========================================================================================================
- PRG="$0"
- # parsing the current command path
- 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
- # get the command path
- PRGDIR=`dirname "$PRG"`
- # PRGDIR maybe ../apache-tomcat-6.0.20/bin
- # get the tomcat home path
- tomcat_dir=`cd "$PRGDIR/.." ; pwd`
- top_dir=`cd "$tomcat_dir/.."; pwd`
- # set the default jdk directory name
- jdk_name="jdk1.6.0_14"
- # get the default jdk path
- jdk_dir="$top_dir/$jdk_name"
- # parse the parameter $2,set the jdk path,if $2 is not empty.
- if [ -n "$2" ]; then
- jdk_dir="$2"
- fi
- # confirm that the jdk path is effective and set the JAVA_HOME environment variable
- if [ -d "$jdk_dir" ]; then
- export JAVA_HOME="$jdk_dir"
- export JRE_HOME="$JAVA_HOME/jre"
- #echo "JRE_HOME is $JRE_HOME"
- else
- echo "The JAVA_HOME environment variable is error,this environment variable is needed to run this program.JAVA_HOME=$jdk_dir."
- echo "The application will exit."
- exit 1
- fi
- # handle the request:start,stop,restart,version
- case "$1" in
- start)
- echo -n $"Tomcat server is starting: "
- "$PRGDIR"/startup.sh >/dev/null
- RETVAL=$?
- if [ $RETVAL -eq 0 ] ; then
- echo "Tomcat server has been started."
- else
- echo "Tomcat server failed to start."
- fi
- echo
- ;;
- stop)
- echo -n $"Tomcat server is stopping: "
- "$PRGDIR"/shutdown.sh >/dev/null
- RETVAL=$?
- if [ $RETVAL -eq 0 ] ; then
- echo "Tomcat server has been stopped."
- else
- echo "Tomcat server failed to stop."
- fi
- echo
- ;;
- version)
- "$PRGDIR"/version.sh
- ;;
- restart|reload)
- $0 stop
- $0 start
- ;;
- *)
- echo $"Usage: $0 {start|stop|restart|version}"
- echo " start Start server"
- echo " stop Stop server"
- echo " restart Restart server"
- echo " version What version of tomcat are you running?"
- exit 1
- esac
- #该片段来自于http://www.codesnippet.cn/detail/15112012376.html
来源: http://www.codesnippet.cn/detail/15112012376.html