1.在etc/init.d/ 目录下新建tomcat文件
2.添加以下内容:
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcatd
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
#这里改为你自己的相应安装目录
export JAVA_HOME=/usr/java/jdk1.8.0_251
export JRE_HOME=/usr/java/jdk1.8.0_251/jre
export CATALINA_HOME=/opt/module/tomcat-9.0.41
export CATALINA_BASE=/opt/module/tomcat-9.0.41
start()
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop()
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 1