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
相关推荐
CYRUS_STUDIO17 分钟前
用 Frida 控制 Android 线程:kill 命令、挂起与恢复全解析
android·linux·逆向
熊猫李2 小时前
rootfs-根文件系统详解
linux
chen9453 小时前
mysql 3节点mgr集群部署
运维·后端
LH_R4 小时前
OneTerm开源堡垒机实战(三):功能扩展与效率提升
运维·后端·安全
dessler4 小时前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
泽泽爱旅行4 小时前
awk 语法解析-前端学习
linux·前端
少妇的美梦1 天前
logstash教程
运维
chen9451 天前
k8s集群部署vector日志采集器
运维
chen9451 天前
aws ec2部署harbor,使用s3存储
运维
轻松Ai享生活1 天前
5 节课深入学习Linux Cgroups
linux