centos7 开机自启java程序

1.脚本文件路径(此为启动tomcat脚本文件  如启动jar文件则需单独书写sh脚本文件  原理相同)

centos7 开机自启java程序_第1张图片

 

 

2.编辑rc.local

vi /etc/rc.d/rc.local

3.修改rc.local文件  在末尾加上一行需要执行的脚本文件即可

#!/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 constrast 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

#开机要启动的sh脚本文件
/home/cmbc/release/bin/startup.sh

4.特别注意要给rc.local赋予执行权限(划重点)

chmod +x /etc/rc.d/rc.local

5.如上述配置仍未开机自启动  需要注意安装jdk和配置环境变量。

你可能感兴趣的:(Linux,java)