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
相关推荐
王二端茶倒水6 小时前
智慧酒店 WiFi 运营:从 Portal 认证到住客体验闭环
运维·物联网·架构
三块可乐两块冰6 小时前
rag学习5
linux·前端·python
::呵呵哒::6 小时前
在macOS/Linux上优雅管理多个JDK版本:环境变量与别名配置指南
java·linux·macos
vortex56 小时前
Witr:系统进程溯源与行为分析工具
linux·运维·服务器
何中应6 小时前
Grafana面板没有数据问题排查
linux·grafana·prometheus
困意少年6 小时前
Linux 命令行参数与环境变量:从 Shell 到 main() 的数据是怎么传进去的?
linux·运维
独隅6 小时前
IntelliJ IDEA 在 Linux 上的完整安装与使用指南
java·linux·intellij-idea
NaclarbCSDN6 小时前
我写了一个命令行书签管理器,然后抛弃了浏览器书签栏
linux·git·python·github
isyangli_blog6 小时前
基于 OpenDaylight 的 SDN 负载均衡应用
运维·负载均衡
ICT系统集成阿祥6 小时前
校园网络准入认证建设与运维经验
运维·网络·智慧校园·经验总结