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
相关推荐
Xの哲學15 分钟前
Linux设备驱动模型深度解剖: 从设计哲学到实战演练
linux·服务器·网络·算法·边缘计算
半夏知半秋31 分钟前
kcp学习-通用的kcp lua绑定
服务器·开发语言·笔记·后端·学习
Ydwlcloud43 分钟前
AWS 2026折扣活动深度解析:寻找最大优惠的智慧路径
大数据·服务器·人工智能·云计算·aws
企业对冲系统官1 小时前
基差风险管理系统集成说明与接口规范
大数据·运维·python·算法·区块链·github
松涛和鸣1 小时前
DAY55 Getting Started with ARM and IMX6ULL
linux·服务器·网络·arm开发·数据库·html
HIT_Weston1 小时前
101、【Ubuntu】【Hugo】搭建私人博客:元信息&翻译(二)
linux·运维·ubuntu
无线图像传输研究探索1 小时前
如何提升机器狗 “超视距” 作战能力?
服务器·网络·5g·机器人·无线图传·机器狗
暮云星影1 小时前
一、linux系统 应用开发:基本认知概念
linux·arm开发
座山雕~2 小时前
docker---部署与常用命令
运维·docker·容器
赵民勇2 小时前
yum命令用法与技巧总结
linux·centos