tomcat服务系统开机自启动脚本
vim /etc/init.d/tomcat
–写入下面启动、停止、重启脚本
#!/bin/bash
#description: Tomcat8 Start Stop Restart
#processname: tomcat8
#chkconfig: 2345 80 05
CATALINA_HOME_CMS=/opt/portal-service/apache-tomcat-8.0.21-cms
CATALINA_HOME_SERVICE=/opt/portal-service/apache-tomcat-8.0.21-service
CATALINA_HOME_MESSAGE=/opt/portal-service/apache-tomcat-8.0.21-message
CATALINA_HOME_CALENDAR=/opt/portal-service/apache-tomcat-8.0.21-calendar
CATALINA_HOME_THIRDPART=/opt/portal-service/apache-tomcat-8.0.21-thirdpart
case $1 in
start)
sh $CATALINA_HOME_CMS/bin/startup.sh
sh $CATALINA_HOME_SERVICE/bin/startup.sh
sh $CATALINA_HOME_MESSAGE/bin/startup.sh
sh $CATALINA_HOME_CALENDAR/bin/startup.sh
sh $CATALINA_HOME_THIRDPART/bin/startup.sh
;;
stop)
sh $CATALINA_HOME_CMS/bin/shutdown.sh
sh $CATALINA_HOME_SERVICE/bin/shutdown.sh
sh $CATALINA_HOME_MESSAGE/bin/shutdown.sh
sh $CATALINA_HOME_CALENDAR/bin/shutdown.sh
sh $CATALINA_HOME_THIRDPART/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME_CMS/bin/startup.sh
sh $CATALINA_HOME_SERVICE/bin/startup.sh
sh $CATALINA_HOME_MESSAGE/bin/startup.sh
sh $CATALINA_HOME_CALENDAR/bin/startup.sh
sh $CATALINA_HOME_THIRDPART/bin/startup.sh
sh $CATALINA_HOME_CMS/bin/shutdown.sh
sh $CATALINA_HOME_SERVICE/bin/shutdown.sh
sh $CATALINA_HOME_MESSAGE/bin/shutdown.sh
sh $CATALINA_HOME_CALENDAR/bin/shutdown.sh
sh $CATALINA_HOME_THIRDPART/bin/shutdown.sh
;;
*)
echo ‘please use : tomcat {start | stop | restart}’
;;
esac
exit 0
注释:chkconfig:2345 80 05 --指定在哪几个级别执行,0一般指关机,6指的是重启,其他为正常启动。80为启动的优先级,05为关闭的优先机
设置系统重启时自动重启服务:
向chkconfig添加 tomcat 服务的管理
chkconfig --add tomcat
设置tomcat服务自启动
chkconfig tomcat on
查看tomcat的启动状态
chkconfig --list | grep tomcat
状态如下:
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
关闭tomcat服务自启动:
chkconfig tomcat off
删除tomcat服务在chkconfig上的管理:
chkconfig –del tomcat
–赋权
sudo chmod -R 777 /etc/init.d/tomcat
–执行脚本,启动、停止 和 重启服务
启动:service tomcat start
停止:service tomcat stop
重启:service tomcat restart