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 shutdown.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"); Except in compliance with
# The License. Obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# unless required by applicable or agreed to writing, software
# Distributed under the License is distributed on a "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.
# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
#
# $Id: shutdown.sh 1130937 2011-06-03 08:27:13z Markt $
# -----------------------------------------------------------------------------
# Resolve Links-a Softlink
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
#上面循环语句的意思是保证文件路径不是一个连接, use loops until you find the original address of the file
#遇到一时看不明白的shell, you can disassemble and run the verification on Linux repeatedly, a little bit of disassembly will understand
#link = ' expr ' $ls ': ' .*-> \ (. *\) $ ' After impersonation: Expr ' lrwxrwxrwx 1 root root 19 March 10:12./bbb.sh H ': ' .*-> \ (. *\) $ '
#很明确的发现是用expr来提取 content of/root/shell/test.sh
#获取这个脚本的目录
Prgdir= ' dirname "$PRG" '
executable=catalina.sh
# Check that target executable exists
if [!-X "$PRGDIR"/"$EXECUTABLE"]; Then
echo "Cannot find $PRGDIR/$EXECUTABLE"
#判断脚本catalina. SH exists and has executable permissions, exits without execution permission
echo "The file is absent or does not has execute permission"
echo "This file was needed to run"
Exit 1
Fi
Exec "$PRGDIR"/"$EXECUTABLE" Stop "[email protected]"
#exec命令在执行时会把当前的shell process closes, and then switches to the following command to continue execution.
#exec命令可以很好的进行脚本之间过渡 and end the previous script so that it does not interfere with the script that is executed later.
#exec command: Often used to replace the current shell and restart a shell, in other words, does not start a child shell. When using this command, any current
#有环境都将会被清除. exec does not overwrite your current shell environment when working with file descriptors, and only then.
Iii. Summary
After interpreting the startup.sh script, you will find shutdown.sh and startup.sh structure and the same, Tomcat shutdown.sh main purpose to find the catalina.sh script location, the start command parameters passed 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/1621402
Tomcat Stop Script shutdown.sh analysis