前言
Java Web应用中如何执行脚本重启Tomcat服务,包含两部分:启停脚本、调用Java代码。
启停脚本
tomcat.sh
#!/bin/sh
#
# -----------------------------------------------------------------------------
# description: Auto-starts tomcat
# Author: ZCQ
# -----------------------------------------------------------------------------
#
# -----------------------------------------------------------------------------
# Environment Variable Prerequisites
#
# TOMCAT_HOME May point at your Catalina "build" directory.
#
# JAVA_HOME Must point at your Java Development Kit installation.
# Required to run the with the "debug" argument.
# -----------------------------------------------------------------------------
# The Return Value
RETVAL=0
# The Operator
user=`whoami`
# SHUTDOWN_WAIT is wait time in seconds for java process to stop
SHUTDOWN_WAIT=5
# The Key Word
key_word="org.apache.catalina.startup.Bootstrap"
# 取出脚本名
cmd="`echo $0 | sed -e 's/^.*\///'`"
echo "**$cmd executed by $user"
# -----------------------------------------------------------------------------
# Check The Enviroment Vair TOMCAT_HOME
# ------------------------------------