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
相关推荐
企服AI产品测评局12 分钟前
2026年Agent元年!深度解析实在Agent未来路线图:从自动化工具到全能数字员工的跃迁
运维·人工智能·ai·chatgpt·自动化
Leo.yuan14 分钟前
运维视角下的数据同步工具选型指南:2026年主流方案功能对比
运维
秋漓16 分钟前
Nginx学习与应用
运维·学习·nginx
TDengine (老段)17 分钟前
TDengine 数据修复与迁移 — VGroup 调度、S3 外挂与运维操作
大数据·运维·数据库·物联网·时序数据库·iot·tdengine
m0_7373025832 分钟前
读懂OpenClaw:新一代开源自主AI智能体的革新与价值
服务器
小白学大数据34 分钟前
爬虫优化:Python 剔除无效超时代理实操
服务器·爬虫·python
utf8mb4安全女神36 分钟前
shell中的判断语法
linux·运维·服务器
iDao技术魔方1 小时前
WSL 配 GPU 用 Docker 的折腾指南(2026 年版)
运维·docker·容器
2601_950368911 小时前
稀土合金粉末采购指南:3步筛选靠谱镁钆供应商
大数据·运维·人工智能·python
mifengxing1 小时前
操作系统(五)
linux·运维·服务器·操作系统·王道考研