主流的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 啟動服務