Centos7伺服器啟動jar包專案最佳方式
阿新 • • 發佈:2018-12-10
在linux上執行jar包誰都會啊。為什麼我還要單獨拎出來講呢。細心的朋友可能已經在標題中發現關鍵詞Centos7和最佳方式。
這就說明我不是隨便寫點東西水一篇部落格的ヾ(◍°∇°◍)ノ゙
首先Centos7 推薦我們這麼執行專案
首先執行命令:
cd /etc/systemd/system
到這個目錄下,新建一個 yourProjectName.service,可以把yourProjectName設定為你想起的服務名
用vi編輯一個新的檔案
vi demo_test.service
檔案內容
[Unit] Description=demo_test#描述 After=syslog.target network.target #依賴 [Service] Type=simple ExecStart=/usr/bin/java -jar /opt/javaapps/demo_test-0.0.1-SNAPSHOT.jar #前面是java命令的絕對路徑 後面是jar包的絕對路徑 ExecStop=/bin/kill -15 $MAINPID User=root Group=root [Install] WantedBy=multi-user.target
使用
systemctl start demo_test
或者
systemctl start demo_test.service
就啟動服務了。
如果更改專案了:
先執行
systemctl daemon-reload
再執行
systemctl start demo_test.service
如果要停止服務:
systemctl stop demo_test
或者
systemctl stop demo_test.service
設定開機自啟動:
systemctl enable demo_test
或者
systemctl enable demo_test.service
又或者不想開機啟動:
systemctl disable demo_test
或者
systemctl disable demo_test.service