I. Analysis and explanation
In order to write a more complete Tomcat launcher script, for code-on-line automation, special analysis under the Tomcat Bin directory of the starup.sh script, learning standard SH script writing method, learn from experience
Second, the script analysis
#!/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 31132os400=falsedarwin=false#os400 is  IBM's Aix#darwin is the operating system component of the macosx operating environment # Darwin is a UNIX-like simulation environment running on the Windows platform case "' uname '" incygwin*) cygwin=true;;o s400*) os400=true;;D arwin*) darwin=true;; Esac# Last Judgment is to determine the operating system, as to whatUse, look down # resolve links - $0 may be a softlink# read script name prg= "$" #test –h File file exists and is a symbolic link (same-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 " fidone# The above loop statement means to ensure that the file path is not a connection, use the loop until you find the original address of the file # encountered a moment to see the shell, you can disassemble after the Linux repeatedly run verification, a little disassembly will understand the #link= ' expr "$ls" : '. *-> \ (. *\) $ ' : expr ' lrwxrwxrwx 1 root root 19 3 month after simulation 17 10:12 ./bbb.sh -> /root/shell/test.sh ' : ' *-> \ (. *\) $ ' #很明确的发现是用expr来提取/root/shell/test.sh content # and this loop can clear its purpose, exclude commands as links, find the real directory of commands, prevent subsequent command errors #获取这个脚本的目录PRGDIR = ' dirname ' $PRG "' Executable=catalina.sh# check that target executable exists# these judgments whether gas is the other operating system if $os 400; 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 is present and has executable permissions, exit echo "Cannot find" without execution permission $PRGDIR/$EXECUTABLE " echo " the file is absent or Does not have execute permission " echo " This file is needed to run this program " exit 1 fifi exec " $PRGDIR "/" $ Executable " start " [email protected] "#exec命令在执行时会把当前的shell process close and then switch to the following command to continue. #exec命令可以很好的进行脚本之间过渡 and end the previous script so that it does not interfere with the script that is executed later. #exec Commands: Often used to replace the current shell and restart a shell, in other words, does not have the shell of the promoter. Any existing # environment will be cleared when using this command. exec when working with file descriptors, only then will,exec not overwrite your current shell environment.
Iii. Summary
Tomcat's startup.sh script is primarily used to determine the environment, locate the catalina.sh script location, and pass the start command arguments to catalina.sh execution.
This article is from the "Ops Road" blog, please be sure to keep this source http://vekergu.blog.51cto.com/9966832/1621396
Tomcat Startup script startup.sh analysis