linux服务器设置Java项目自启动

一、概述
      系统为centos7系统

二、开机自启动jar
      xilanapp.jar

三、编写脚本
      文件存放位置和名字自己定义,此处为startup.sh,存放位置为jar包位置

    # !/bin/bash
    # program
    # file preview server star
    #java
    export JAVA_HOME=/usr/java/jdk1.8.0_231-amd64
    export PATH=${JAVA_HOME}/bin:$PATH

    nohup java -jar /opt/app/xilanapp.jar >/opt/app/nohup.out 2>&1 &
    chmod 777 /opt/app/nohup.out

    说明:如果没有vim工具,可以使用yum install vim 即可下载,或者使用vi,系统默认自带;编辑文件时先按i建,编辑完后按esc退出,再按:wq 保存并退出

四、给startup.sh添加执行权限
      chmod +x startup.sh

五、编辑rc.local文件
       在rc.local文件末尾添加startup.sh文件的路径,保存退出
       vim  /etc/rc.d/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 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

    su - root -c '/opt/app/startup.sh'

六、授予rc.local文件权限
      chmod +x /etc/rc.d/rc.local

七、重启系统 
      reboot

八、重启后查看jar是否已启动
      ps  -ef |grep  java

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值