可直接将下面的shell脚本进行复制,修改主要字段后直接使用。
#!/bin/bash
#
# tomcat startup script for the Tomcat server
#
#
# chkconfig: 345 80 20
# description: start the tomcat deamon
#
# Source function library
. /etc/rc.d/init.d/functions
prog=tomcat8
JAVA_HOME=/usr/java/jdk1.8.0_201-amd64 需要按照实际的环境进行修改
export JAVA_HOME
CATALANA_HOME=/root/apache-tomcat-8.5.37 按照实际的环境配置
export CATALINA_HOME
case "$1" in
start)
echo "Starting Tomcat..."
$CATALANA_HOME/bin/startup.sh
;;
stop)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin/shutdown.sh
;;
restart)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin/shutdown.sh
sleep 2
echo
echo "Starting Tomcat..."
$CATALANA_HOME/bin/startup.sh
;;
*)
echo "Usage: $prog {start|stop|restart}"
;;
esac
exit 0
配置步骤
[root@localhost /]# cd /etc/init.d/
[root@localhost init.d]# chmod 755 tomcat8 #赋予权限
[root@localhost init.d]# service tomcat8 start #启动服务
Starting tomcat8 (via systemctl): [ 确定 ]
[root@localhost init.d]# service tomcat8 stop #停止服务
Stopping tomcat8 (via systemctl): [ 确定 ]
[root@localhost init.d]# service tomcat8 restart #重启服务
Restarting tomcat8 (via systemctl): [ 确定 ]
[root@localhost zm]# chkconfig tomcat8 on #服务脚本加入到系统启动队列
[root@localhost zm]# chkconfig --list tomcat8 #检查 oracle服务是否已经生效