Tomcat stop script shutdown. sh Analysis
I. Analysis description
In order to write a more complete tomcat STARTUP script for automated code launch, the shutdown under the bin directory of tomcat is analyzed. sh script, learn how to compile the standard sh script, and learn from it
Ii. Script Analysis
#! /Bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# Contributor license agreements. See the NOTICE file distributed
# 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 T in compliance
# The License. You may obtain a copy of the License
#
# 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.
#-----------------------------------------------------------------------------
# Stop script for the CATALINA Server
#
# $ Id: shutdown. sh 1130937 2011-06-03 08: 27: 13Z markt $
#-----------------------------------------------------------------------------
# Resolve links-$0 may be a softlink
PRG = "$0"
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
# The preceding loop statement ensures that the file path is not a connection. Use the loop until the original file address is found.
# If you encounter a shell that you cannot understand at the moment, you can disassemble it and run the verification repeatedly in linux. You will understand it after a little disassembly.
# Link = 'expr "$ ls ":'. *-> \(. * \) $ ''after simulation: expr 'lrwxrwxrwx 1 root 19 aug 17 10:12. /bbb. sh->/root/shell/test. sh ':'. *-> \(. * \) $'
# It is clear that expr is used to extract/root/shell/test. sh content.
# Obtain the directory of the script
PRGDIR = 'dirname "$ PRG "'
EXECUTABLE = catalina. sh
# Check that target executable exists
If [! -X "$ PRGDIR"/"$ EXECUTABLE"]; then
Echo "Cannot find $ PRGDIR/$ EXECUTABLE"
# Determine whether the script catalina. sh exists and has the executable permission. If you do not have the execution permission, exit.
Echo "The file is absent or does not have execute permission"
Echo "This file is needed to run this program"
Exit 1
Fi
Exec "$ PRGDIR"/"$ EXECUTABLE" stop "$ @"
# When executing the exec command, the current shell process will be closed, and the subsequent command will be switched to continue the execution.
# The exec command can perform a good transition between scripts and end the previous script without interfering with the subsequent scripts.
# Exec command: It is often used to replace the current shell and restart a shell. In other words, there is no starting shell. When you use this command
# All environments will be cleared. When exec operates on file descriptors, it is only in this case that exec will not overwrite your current shell environment.
Iii. Summary
After reading startup. sh script, you will find shutdown. sh and startup. THE sh structure is the same as that of tomcat shutdown. sh mainly aims to find catalina. sh script location to pass the startup command parameters to catalina. sh. However, catalina. THE sh script also involves determining the system environment and finding catalina. sh script is related to the original path, so startup is not required when tomcat is started. sh script (shutdown in the next analysis. sh), directly. /catalina. sh start | stop | restart.
In the next article, the author will analyze catalina. sh script execution principle, so as to fully understand the tomcat startup process and need to pay attention to the details, to provide knowledge reserves for tomcat use and exclusion, where the text is incorrect, forget the majority of O & M friends to correct the opinion.
Install JDK + Tomcat in RedHat Linux 5.5 and deploy Java Projects
Tomcat authoritative guide (second edition) (Chinese/English hd pdf + bookmarks)
Tomcat Security Configuration and Performance Optimization
How to Use Xshell to view Tomcat real-time logs with Chinese garbled characters in Linux
Install JDK and Tomcat in CentOS 64-bit and set the Tomcat Startup Procedure
Install Tomcat in CentOS 6.5
Tomcat details: click here
Tomcat: click here
This article permanently updates the link address: