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
相关推荐
Ronin3059 分钟前
【Linux网络】传输层协议UDP
linux·网络·udp·传输层
ycydynq33 分钟前
python html 解析的一些写法
linux·python·html
A***279534 分钟前
后端服务限流配置,Spring Cloud Gateway
java·运维·数据库
n***265635 分钟前
Nginx反向代理出现502 Bad Gateway问题的解决方案
运维·nginx·gateway
知识分享小能手36 分钟前
openEuler入门学习教程,从入门到精通,openEuler 24.03 中的 Vim 编辑器 —— 全面知识点详解(7)
linux·vim·openeuler
ITVV1 小时前
Docker 安装配置
运维·docker·容器
圣诞节不感冒1 小时前
nginx动态域名解析(利用变量触发域名动态解析)
运维·nginx
LCG元1 小时前
Linux 性能监控三板斧:top/vmstat/iostat 快速入门
linux
LCG元1 小时前
实战案例:服务器磁盘空间告急,如何快速定位和清理"大文件"
linux
以琦琦为中心1 小时前
很好!从 `fdisk -l` 输出可以看到您的磁盘确实是600GB,但只有29.5GB被分配给根分区 `/dev/sda3`。现在我来帮您扩展这个分区。
linux·ubuntu