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
相关推荐
ltl6 小时前
校验和与数据完整性:CRC32C、xxHash 与端到端校验
linux
我是小灰灰吖7 小时前
Ubuntu 22.04 设置 CPU 性能模式:提升系统响应速度
linux·ubuntu
ltl7 小时前
持续性能分析:Parca、Pyroscope、Grafana Beyla
linux
ltl7 小时前
Direct I/O 与 O_DIRECT:绕过缓存的得与失
linux
盐焗鹌鹑蛋8 小时前
【Linux】进程控制
linux
微三云 - 廖会灵 (私域系统开发)9 小时前
抖店 OPC 自动化运营系统架构与商业代理分控体系完整解析
运维·系统架构·自动化
G31135422739 小时前
大模型不可用时,业务还能不能继续:企业需要设计降级方案
大数据·服务器·数据库·人工智能·深度学习
办公室马主任10 小时前
华南机械加工企业选MES服务商怎么选?
大数据·运维·人工智能·制造
盐焗鹌鹑蛋10 小时前
【Linux】进程程序替换
linux
鸠摩智首席音效师10 小时前
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead
linux