將應用注冊為Linux的服務


主流的Linux大多使用init.d或systemd來注冊服務。下面以centos6.6演示init.d注冊服務;以centos7.1演示systemd注冊服務。

 1. 基於Linux的init.d部署

sudo ln -s /var/apps/xxxx.jar  /etc/init.d/test

其中 test就是服務名

service test start    啟動服務

service test stop   停止服務

service test status  服務狀態

chkconfig test on       開機啟動

 

  2.  基於Linux的systemd部署

在/etc/systemd/system/目錄下新建文件test.service,填入下面內容:

[Unit]

Description=test

After=syslog.target

[Serive]

ExecStart=/usr/bin/java -jar  /var/app/XXX.jar

[Install]

WantedBy=multi-user.target

注意,在實際使用中修改Description和ExecStart后面的內容

systemctl start test 或  systemctl start test.service           啟動服務

systemctl stop test 或  systemctl stop test.service           停止服務

systemctl status test 或  systemctl status test.service       服務狀態

systemctl enable test 或  systemctl enable test.service       開機啟動

journalctl -u test 或  journalctl -u test.service           啟動服務

 


免責聲明!

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



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