1
通過Ansible將獨立.jar作爲服務運行的最佳方法是什麼?在Ubuntu上通過Ansible運行Java Jar as Service
我需要在Ubuntu EC2主機上通過ansible運行metabase.jar。
我應該守護它嗎?有沒有推薦的方法或庫?
理想情況下,如果可能的話,我想通過Ansible處理程序管理狀態。
感謝
通過Ansible將獨立.jar作爲服務運行的最佳方法是什麼?在Ubuntu上通過Ansible運行Java Jar as Service
我需要在Ubuntu EC2主機上通過ansible運行metabase.jar。
我應該守護它嗎?有沒有推薦的方法或庫?
理想情況下,如果可能的話,我想通過Ansible處理程序管理狀態。
感謝
根據您的底層箱的初始系統(init.d中或systemctl)有兩種方法。
的init.d
隨着ansible你可以在
/etc/init.d/<your_service_name>
然後可以使用ansible的服務模塊創建應用程序的jar的符號鏈接管理 服務的狀態
- service:
name: <your_service_name>
state: restarted
更多信息:Ansible service module documentation
systemctl
如果你的init方法systemd你必須創建一個非常簡單的單元文件
[Unit]
Description=<Description>
[Service]
ExecStart=/path/to/<your_app>.jar
[Install]
WantedBy=multi-user.target
複製單位文件
/etc/systemd/service/<your_unit_file>.service
然後你可以我們Ëansible的systemd模塊管理服務的狀態
- name: Start Service
systemd:
name: <your service name>
state: started
的感謝!將嘗試! – RedRobot
儘管服務文件必須放在''/ etc/systemd/system'''中,否則正確 – RedRobot
更改了我的答案中的路徑。太棒了,它爲你工作。 –