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
相关推荐
用户0413284651312 分钟前
Linux 查看端口占用的 6 种方法:ss、netstat、lsof 实战
linux
2301_7807896616 分钟前
WAF与Web应用安全的深度融合:从边界防护到业务风控
运维·服务器·网络·云原生·ddos
二宝哥17 分钟前
Rocky Linux 10.2 安装 PostgreSQL 15 完整教程
linux·运维·postgresql
不会就选b18 分钟前
Linux之线程池(二)
linux·运维·服务器
M78佐菲21 分钟前
Linux学习笔记:进程回收、exec函数簇与线程
linux·笔记·学习·算法
OpenFDE开源桌面22 分钟前
实操:如何将安卓 App与Linux系统应用级融合(附代码)
android·linux
Nontee28 分钟前
Quartz 集群 + 策略模式:逾期预警推送系统设计实录
linux·服务器·策略模式
工业HMI实战笔记32 分钟前
【拯救HMI】:工业自动化交互革命:HMI 触摸屏如何成为产线智能中枢
运维·自动化·交互
NJCloud35 分钟前
Openstack(一)——基础环境配置与依赖服务安装
linux·架构·openstack
AlanBruce1 小时前
一键设备扫描功能详解
服务器·网络·网络协议·modbus·摩尔信使·设备扫描