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 小时前
Docker+cpolar 实战:打造灵活可控的远程办公系统
运维·docker·容器
其实防守也摸鱼1 小时前
运维--怎么看接口的请求和返回
运维·学习·网络安全·网络攻击模型·burpsuite·攻防对抗·蓝队
weixin_307779132 小时前
Linux下Nginx故障系统化检查Shell脚本
linux·运维·服务器·nginx·自动化
skyutuzz3 小时前
node安装部署
linux
一次旅行3 小时前
【AI工具】Rust-Based CLI:用 xargs 和并行加速你的 Linux 日常
linux·开发语言·rust
山峰哥4 小时前
数据库工程与索引策略实战指南‌
服务器·数据库·sql·oracle·深度优先
jieyucx4 小时前
Docker 入门第一阶段:建立正确认知与初体验
运维·docker·容器
qetfw6 小时前
CentOS 7 基础环境配置
linux·运维·centos
天空'之城6 小时前
Linux 系统编程 21:守护进程与日志系统全解
linux·系统编程·日志系统·守护进程
jieyucx7 小时前
Docker 入门第二阶段:掌握日常命令
运维·docker·容器