Linux系统下tomcat服务自动重启

1.修改系统启动时脚本文件

bash 复制代码
vi /etc/rc.d/rc.local
bash 复制代码
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
export JAVA_HOME=/home/jdk1.8.0_231
/home/apache-tomcat-8.5.68/bin/shutdown.sh
/home/apache-tomcat-8.5.68/bin/startup.sh

注意:脚本可能报错找不到java环境,所以加上export JAVA_HOME=/home/jdk1.8.0_231,另外tomcat需要先关闭再启动,不然进程一直存在导致启动失败

2.检查rc.local服务是否启动

bash 复制代码
 systemctl list-unit-files|grep rc.local
 # static表示已开启
 # disable未开启 如果没开启执行下面命令
 systemctl start rc.local.service

3.给文件授权

bash 复制代码
chmod +x /etc/rc.d/rc.local

4.关闭tomcat,手动执行脚本,看是否启动

bash 复制代码
sudo /etc/rc.d/rc.local

5.服务器重启测试

bash 复制代码
reboot
相关推荐
Elastic 中国社区官方博客几秒前
从建议到修复的 4 个阶段:使用 Elastic Workflows 实现人在回路中的自动化
运维·数据库·人工智能·后端·elasticsearch·ai·自动化
淡海水5 分钟前
05-03-栈队列-PriorityQueue-TElement-TPriority-NET6优先队列语义与四叉堆实现
服务器·前端·c#·priorityqueue·clr·telement
土星云SaturnCloud7 分钟前
大型仓储AI视觉全场景落地实战:安全·效率·库存,32TOPS土星云边缘算力赋能分区部署
服务器·人工智能·ai·边缘计算
jing.wang_202514 分钟前
制作一个带用户操作界面的精简Linux操作系统
linux·服务器
北京靠谱的GEO优化机构14 分钟前
海外推广:没有媒体内容,SEO就是“无米之炊“
服务器·数据库·媒体
段帅星31 分钟前
Mac + iTerm2 运维终端配置参考
运维
智恒百亿1 小时前
从开箱到跑通大模型:一台 RTX 5090 八卡服务器的部署实录(附踩坑清单)
运维·服务器
沫璃染墨1 小时前
《从零入门Linux系统篇(三十二):文件篇·五——深入理解磁盘:从物理结构到LBA寻址》
linux·运维·服务器·系统架构·硬件架构
Songxwn1 小时前
Rack-auto 裸金属服务器自动化
运维·服务器·自动化
zlwool1 小时前
非标设备厂图纸管理选型实战
运维·服务器·erp·设备erp·非标机械