在centos7中將jar註冊爲服務

新建文件並保存爲/u01/shell/acexe-ym-rmi-service-start

#!/bin/sh

export JAVA_HOME=/usr/java/jdk1.8.0_181-amd64/jre/bin/java
export PATH=$JAVA_HOME/bin:$PATH

java -jar /u01/service/acexe-ym-rmi-service.jar > /u01/logs/acexe-ym-rmi-service.log &
echo $! > /var/run/acexe-ym-rmi-service.pid

新建文件並保存爲/u01/shell/acexe-ym-rmi-service-stop 

#!/bin/sh

PID=$(cat /var/run/acexe-ym-rmi-service.pid)
kill -9 $PID

將下面的文件保存爲/usr/lib/systemd/system/acexe-ym-rmi-service.service 因爲systemd進程會去讀取該目錄下的文件啓動爲服務

[Unit]
Description=acexe-ym-rmi-service
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/u01/shell/acexe-ym-rmi-service-start
ExecStop=/u01/shell/acexe-ym-rmi-service-stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

啓動服務 systemctl start  acexe-ym-rmi-service.service

查看服務 systemctl status  acexe-ym-rmi-service.service

停止服務 systemctl stop  acexe-ym-rmi-service.service

注意如果顯示code=exited, status=203/EXEC 可能是權限的問題 chmod -R 777 * 處理

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章