编写tomcat服务脚本文件
在/etc目录下创建tomcat服务脚本文件。
[root@localhost /]# touch tomcat
[root@localhost /]# vim /etctomcat
将下面内容进行粘贴:
#!/bin/bash
#
# tomcat startup script for the Tomcat server
#
#
# chkconfig: 345 80 20
# description: start the tomcat deamon
#
# Source function library
. /etc/rc.dfunctions
prog=tomcat
java_HOME=/usr/java # 根据自己的路径改写JAVA_HOME
export JAVA_HOME
CATALANA_HOME=/usr/local/tomcat/ # 根据自己的路径改写CATALANA_HOME
export CATALINA_HOME
case "$1" in
start)
echo "Starting Tomcat..."
$CATALANA_HOME/bin
;;
stop)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin
;;
restart)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin
sleep 2
echo
echo "Starting Tomcat..."
$CATALANA_HOME/bin
;;
*)
echo "Usage: $prog {start|stop|restart}"
;;
esac
exit 0
赋权限,测试启动脚本
[root@localhost /]# cd /etc
[root@localhost init.d]# chmod 755 tomcat #赋予权限
[root@localhost init.d]# service tomcat8 start #启动服务
Starting tomcat8 (via systemctl): [ 确定 ]
[root@localhost init.d]# service tomcat stop #停止服务
Stopping tomcat8 (via systemctl): [ 确定 ]
[root@localhost init.d]# service tomcat restart #重启服务
Restarting tomcat8 (via systemctl): [ 确定 ]
将服务脚本加入到系统启动队列
[root@localhost zm]# chkconfig tomcat on #服务脚本加入到系统启动队列
[root@localhost zm]# chkconfig --list tomcat #检查 oracle服务是否已经生效
最后验证下脚本是否可以启动和停止tomcat
[root@localhost zm]# service tomcat stop
[root@localhost zm]# service tomcat start