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
相关推荐
..过云雨1 分钟前
TCP/IP网络传输的基本要素剖析
linux·网络·网络协议·tcp/ip
乾元18 分钟前
边缘计算网络的自动流量分配与用户感知 QoE 优化——从“链路最优”到“体验最优”的网络控制闭环
运维·网络·人工智能·网络协议·重构·边缘计算
一个平凡而乐于分享的小比特22 分钟前
Ubuntu下TFTP与FTP服务详解
linux·ubuntu·ftp·tftp
haluhalu.25 分钟前
Linux--System V 共享内存完全指南:从原理到实践
linux·运维·服务器
oMcLin25 分钟前
如何在Debian 11服务器上部署并优化高性能Elasticsearch集群,处理PB级数据?
服务器·elasticsearch·debian
prettyxian27 分钟前
【linux】深入Linux进程调度:运行、睡眠、僵尸与不可杀死的D状态
linux·服务器
宋情写29 分钟前
OpenEuler安装docker
运维·docker·容器
想唱rap30 分钟前
缓冲区的理解和实现
java·服务器·前端·c++·python
少云清32 分钟前
【接口测试】3_持续集成 _Jenkins
运维·ci/cd·jenkins