linux开机自启动jar
一、概述
系统为centos7系统
二、开机自启动jar
mine-register.jar materials-gateway.jar materials-upms-biz.jar materials-oauth.jar materials-manager.jar imine-gis.jar oss.jar
三、编写脚本
文件存放位置和名字自己定义,此处为startup.sh,存放位置为jar包位置
vim startup.sh
在打开的文件中输入下面信息保存退出(也可以使用finalshell直接图形操作新建文件保存),注意java的安装路径
# !/bin/bash # program # file preview server star #java export JAVA_HOME=/usr/local/jdk8u275-b01 export PATH=${JAVA_HOME}/bin:$PATH export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib export JRE=${JAVA_HOME}/jre nohup java -jar /root/mine-register.jar >mine-register.log 2>&1 & sleep 30 nohup java -jar /root/oss.jar>/root/oss.log 2>&1 & nohup java -jar /root/materials-gateway.jar >/root/gateway.log 2>&1 & nohup java -jar /root/materials-upms-biz.jar>/root/upms-biz.log 2>&1 & nohup java -jar /root/materials-oauth.jar >/root/oauth.log 2>&1 & nohup java -jar /root/imine-gis.jar >/root/gis.log 2>&1 & nohup java -jar /root/materials-manager.jar >/root/manager.log 2>&1 &
说明:如果没有vim工具,可以使用yum install vim 即可下载,或者使用vi,系统默认自带;编辑文件时先按i建,编辑完后按esc退出,再按:wq 保存并退出
四、给startup.sh添加执行权限
chmod +x startup.sh
五、编辑rc.local文件
vim /etc/rc.d/rc.local 再rc.local文件末尾添加startup.sh文件的路径,保存退出 #!/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 /root/startup.sh
六、授予rc.local文件权限
chmod +x /etc/rc.d/rc.local
七重启系统
reboot
八 重启后查看jar是否已启动
ps -ef |grep java
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号