在CentOS上创建tomcat服务脚本的步骤如下:
/etc/init.d/
目录下创建一个新的脚本文件,比如tomcat
:sudo vi /etc/init.d/tomcat
#!/bin/bash
# Tomcat auto-start
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
PROG_PATH=/opt/apache-tomcat-9.0.37
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export CATALINA_HOME=$PROG_PATH
export CATALINA_BASE=$PROG_PATH
export CATALINA_PID=$CATALINA_BASE/tomcat.pid
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0
tomcat
脚本文件添加可执行权限:sudo chmod +x /etc/init.d/tomcat
chkconfig
命令将tomcat服务添加到系统服务中:sudo chkconfig --add tomcat
sudo chkconfig tomcat on
现在,您可以通过以下命令启动、停止和重启Tomcat服务:
sudo service tomcat start
sudo service tomcat stop
sudo service tomcat restart