为Tomcat添加启动停止重启
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为Tomcat添加启动停止重启相关的知识,希望对你有一定的参考价值。
#安装tomcat
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-9/v9.0.0.M4/bin/apache-tomcat-9.0.0.M4.tar.gz?crazycache=1
tar zxvf apache-tomcat-9.0.0.M4.tar.gz
mv apache-tomcat-9.0.0.M4.tar.gz /usr/local/tomcat
cd /usr/local/tomcat/bin
sh startup.sh
#设置开机启动(增加restart)
cd /etc/init.d
vi tomcat
#!/bin/bash
#
# tomcat
#
# chkconfig:
# description: Start up the Tomcat servlet engine.
# Source function library.
. /etc/init.d/functions
RETVAL=$?
CATALINA_HOME="/usr/local/tomcat"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
/bin/su root $CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
/bin/su root $CATALINA_HOME/bin/shutdown.sh
fi
;;
restart)
if [ lsof -i:8080 ];
then
/bin/su root $CATALINA_HOME/bin/shutdown.sh
echo $"Stop Tomcat OK"
fi
echo $"Tomcat NOT Run"
/bin/su root $CATALINA_HOME/bin/startup.sh
echo $"Starting Tomcat OK"
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
以上是关于为Tomcat添加启动停止重启的主要内容,如果未能解决你的问题,请参考以下文章
centos7中使用yum安装tomcat以及它的启动停止重启