一、分析说明
    为了写出更加完善的tomcat启动方面的自动化脚本,健壮自己用于代码上线自动化部署的脚本,特分析下tomcat的bin目录下的starup.sh脚本,学习标准的sh脚本的编写方法,从中吸取经验

二、脚本分析
#!/bin/sh 
# Licensed to the Apache Software Foundation (ASF) under one or more 
# contributor license agreements.  See the NOTICE file distributed with 
# this work for additional information regarding copyright ownership. 
# The ASF licenses this file to You under the Apache License, Version 2.0 
# (the "License"); you may not use this file except in compliance with 
# the License.  You may obtain a copy of the License at 

#    http://www.apache.org/licenses/LICENSE-2.0 

# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License. 
# ----------------------------------------------------------------------------- 
# Start Script for the CATALINA Server 

# $Id: startup.sh 1130937 2011-06-03 08:27:13Z markt $ 
# ----------------------------------------------------------------------------- 
# Better OS/400 detection: see Bugzilla 31132 
os400=false
darwin=false
#os400是 IBM的AIX 
#darwin是MacOSX 操作环境的操作系统成份 
#Darwin是windows平台上运行的类UNIX模拟环境 
case "`uname`" in
CYGWIN*) cygwin=true;; 
OS400*) os400=true;; 
Darwin*) darwin=true;; 
esac
#上一个判断是为了判断操作系统,至于何用,往下看 
# resolve links - $0 may be a softlink 
#读取脚本名 
PRG="$0"
#test –h File 文件存在并且是一个符号链接(同-L) 
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
#上面循环语句的意思是保证文件路径不是一个连接,使用循环直至找到文件原地址 
#遇到一时看不明白的shell,可以拆解后自己在linux反复运行验证,一点点拆解就会明白的 
#link=`expr "$ls" : '.*-> \(.*\)$'` 模拟后: expr 'lrwxrwxrwx 1 root root 19 3月  17 10:12 ./bbb.sh -> /root/shell/test.sh' : '.*-> \(.*\)$' 
#很明确的发现是用expr来提取/root/shell/test.sh的内容 
#而这个循环就可以明确其目的,排除命令为链接,找出命令真正的目录,防止后面的命令出错  
#这段代码如果在以后有这方面的找出链接源头的需求可以完全借鉴 
  
#获取这个脚本的目录 
PRGDIR=`dirname "$PRG"` 
EXECUTABLE=catalina.sh 
# Check that target executable exists 
#这些判断是否气是其他的操作系统 
if $os400; then
  # -x will Only work on the os400 if the files are:  
  # 1. owned by the user 
  # 2. owned by the PRIMARY group of the user 
  # this will not work if the user belongs in secondary groups 
  eval
  #这个eval还没有理解 
else
  if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
  #判断脚本catalina.sh是否存在并有可执行权限,没有执行权限就退出  
    echo "Cannot find $PRGDIR/$EXECUTABLE"
    echo "The file is absent or does not have execute permission"
    echo "This file is needed to run this program"
    exit 1 
  fi
fi 
exec "$PRGDIR"/"$EXECUTABLE" start "$@"
#exec命令在执行时会把当前的shell process关闭,然后换到后面的命令继续执行。 
#exec命令可以很好的进行脚本之间过渡,并且结束掉前一个脚本这样不会对后面执行的脚本造成干扰。 
#exec 命令:常用来替代当前 shell 并重新启动一个 shell,换句话说,并没有启动子 shell。使用这一命令时任何现 
#有环境都将会被清除。exec 在对文件描述符进行操作的时候,也只有在这时,exec 不会覆盖你当前的 shell 环境。 
#exec 可以用于脚本执行完启动需要启动另一个脚本是使用,但须考虑到环境变量是否被继承。

三、总结
    tomcat的startup.sh脚本主要用来判断环境,找到catalina.sh脚本源路径,将启动命令参数传递给catalina.sh执行。然而catalina.sh脚本中也涉及到判断系统环境和找到catalina.sh脚本原路径的相关代码,所以执行tomcat启动时,无需使用startup.sh脚本(下一篇分析的shutdown.sh也类似,见 ),直接./catalina.sh start|stop|restart 即可。

转载于:https://blog.51cto.com/felixzhang/1855486

Tomcat启动脚本startup.sh分析相关推荐

  1. linux tomcat startup.sh,tomcat启动脚本startup.sh分析

    一.分析说明 为了写出更加完善的tomcat启动方面的自动化脚本,健壮自己用于代码上线自动化部署的脚本,特分析下tomcat的bin目录下的starup.sh脚本,学习标准的sh脚本的编写方法,从中吸 ...

  2. linux startup.sh文件所在目录,Tomcat启动脚本startup.sh分析

    一.分析说明 为了写出更加完善的tomcat启动方面的自动化脚本,健壮自己用于代码上线自动化部署的脚本,特分析下tomcat的bin目录下的starup.sh脚本,学习标准的sh脚本的编写方法,从中吸 ...

  3. tomcat启动:startup.sh、catalina.sh、setclasspath.sh三者关系

    1.概述 JavaWeb项目发布tomcat容器,我们一般是到tomcat下的bin/startup.sh直接运行.很少去了解tomcat底层启动细节. 后来实际开发中,需要在tomcat中显式配置- ...

  4. tomcat变量环境脚本setclasspath.sh分析

    之所以分析setclasspath.sh脚本,是因为catalina.sh脚本会引用到这个脚本,如果不对其进行分析,之后看catalina.sh脚本就会不知道一些变量没有申明和赋值怎么会跑出来,本篇文 ...

  5. tomcatSupplement(1)tomcat启动脚本分析(以Windows平台为例)

    [0]README 1)本文部分文字描述转自:"深入剖析tomcat",旨在学习"tomcat启动脚本分析"的相关知识: 2)for tomcat4 start ...

  6. CentOS 7 启动Tomcat 报错 “ ./startup.sh: Permission denied” 解决方案及问题总结

    一.解决方案 在apache-tomcat的bin目录下,输入 ./start.up无法启动Tomcat,显示 " -bash: ./startup.sh: Permission denie ...

  7. Tomcat学习总结(20)—— Tomcat启动脚本收藏

    前言 有这样一个场景,公司为了安全起见,需要对所有登录Linux服务器做安全限制,要求除了管理员其他要登录linux服务器的员工不能用最高权限账号登录,要创建新的用户,对目录及文件权限做出控制,只能对 ...

  8. Linux qt程序打包依赖库,Linux打包免安装的Qt程序(编写导出依赖包的脚本copylib.sh,程序启动脚本MyApp.sh)...

    本文介绍如何打包Qt程序,使其在没有安装Qt的系统可以运行. 默认前提:另外一个系统和本系统是同一个系统版本. 1,编写导出依赖包的脚本copylib.sh #!/bin/bash LibDir=$P ...

  9. 全志a64linux内核编译,全志A64 lichee编译脚本build.sh分析

    全志A64 lichee编译脚本build.sh分析 发布时间:2018-08-22 15:58, 浏览次数:269 , 标签: lichee build sh lichee目录下的./build.s ...

最新文章

  1. day7 面向对象进阶、socket套接字
  2. python dry原则_python使用建议与技巧分享(一)
  3. python语句块标记_Python简单语句
  4. BZOJ 2208[Jsoi2010]连通数
  5. python-3.6.2安装
  6. 携程试点每周两天居家办公反响热烈,76%的员工主动报名
  7. mm1排队系统仿真matlab实验报告,MM1排队系统仿真matlab实验报告.doc
  8. Spark(Hive)对字符串数值的排序
  9. decorator 装饰
  10. 用pathon实现计算器功能
  11. BZOJ 2432 兔农
  12. Fama-French五因子模型实用攻略
  13. 使用Coverity进行代码检测,构建C#报错,The Web-app security checkers are fully suppored only on Windwds.
  14. FFT 采样频率和采样点数的选取
  15. 2db多少功率_db与w换算(1db等于多少功率)
  16. 线性齐次方程组的通解 MATLAB
  17. mac下chrome插件安装位置
  18. 学习——学习能力是最重要的能力
  19. 宿主机无法访问docker容器的坑
  20. PDF预览、支持ie、谷歌等主流浏览器

热门文章

  1. python写一个文件下载器_python使用tcp实现一个简单的下载器
  2. 神策数据:从技术视角看,如何更多、更好、更快地实施A/B试验
  3. 4 个关键步骤打造用户满意的产品体验
  4. 神策数据首度公开「电商行业事件设计埋点模板」
  5. linux网卡Bond模式
  6. 浏览器是如何展示网页的
  7. CserialPort类的简单用法
  8. Intellectual Property Essentials for Start-Ups
  9. pigeon hole
  10. what to do preparing for phd