部署jar到linux ,開機自啟動


1.新建/etc/init.d/myService.sh shell文件

 

#!/bin/sh
# chkconfig: 2345 85 15
#description:auto_run
#程序名
RUN_NAME="bi-operation-support-web-advertisement-1.0.jar"
#jar 位置
JAVA_OPTS=/etc/systemd/system/bi-operation-support-web-advertisement-1.0.jar

#開始方法
start() {
        nohup java -jar $JAVA_OPTS &
        echo "$RUN_NAME started success."
}

#結束方法
stop() {
        echo "stopping $RUN_NAME ..."
        kill -9 `ps -ef|grep $JAVA_OPTS|grep -v grep|grep -v stop|awk '{print $2}'`
}

case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        restart)
            stop
            start
            ;;
        *)
                echo "Userage: $0 {start|stop|restart}"
                exit 1
esac

2.給sh文件和jar可執行權限

chmod +x /etc/init.d/myService.sh

chmod +x /etc/init.d/bi-operation-support-web-advertisement-1.0.jar

 

2. 添加chkconfig

chkconfig --add myService.sh          (首先,添加為系統服務,注意add前面有兩個橫杠)

chkconfig myService.sh on  (開機自啟動)

chkconfig --list (列表顯示)

service myService.sh start(啟動服務,就是執行my的腳本)

 

 添加權限

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM