Linux开机自启动Jar包,Linux断电重启自动启服务,使用 /etc/rc.d/rc.local启动

 

使用 /etc/rc.d/rc.local配置:

输入命令:

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

这句话的意思是 授予 /etc/rc.d/rc.local 文件执行权限

然后我们创建启动文件 runJar.sh

 
  1. #!/bin/bash

  2.  
  3. export JAVA_HOME=/usr/local/jdk1.8.0_171

  4. export JRE_HOME=/usr/local/jdk1.8.0_171/jre

  5. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH

  6. export PATH=$JAVA_HOME/bin:$PATH

  7.  
  8. cd /home/

  9. nohup java -jar jcmes-center-0.0.1-SNAPSHOT.jar >center.log 2>&1 &

  10. nohup java -jar jcmes-security-login-0.0.1-SNAPSHOT.jar >login.log 2>&1 &

  11. nohup java -jar jcmes-card-0.0.1-SNAPSHOT.jar >card.log 2>&1

这里我们选择是以生成log的方式启动jar包。

启动几个jar 就在后边添加,注意jdk的环境变量填写正确

cd /home/ 的意思是 进入jar包目录

接下来我们赋予runJar.sh 执行权限

chmod +x /home/runJar.sh

最关键的步骤

运行命令 

vi /etc/rc.d/rc.local

编辑 rc.local文件

 
  1. #!/bin/bash

  2. # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES

  3. #

  4. # It is highly advisable to create own systemd services or udev rules

  5. # to run scripts during boot instead of using this file.

  6. #

  7. # In contrast to previous versions due to parallel execution during boot

  8. # this script will NOT be run after all other services.

  9. #

  10. # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure

  11. # that this script will be executed during boot.

  12.  
  13. touch /var/lock/subsys/local

  14. /home/runJar2.sh

注意最后一行 加入我们的启动文件

最后 重启服务器

[root@localhost ~]# reboot

我们看是否已经启动

 
  1. [root@localhost ~]# ps -ef | grep java

  2. root 917 1 48 23:40 ? 00:00:11 java -jar jcmes-center-0.0.1-SNAPSHOT.jar

  3. root 918 1 42 23:40 ? 00:00:09 java -jar jcmes-security-login-0.0.1-SNAPSHOT.jar

  4. root 1091 1070 0 23:40 pts/0 00:00:00 grep --color=auto java

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值