2017-04-24 85 views
1

通过Ansible将独立.jar作为服务运行的最佳方法是什么?在Ubuntu上通过Ansible运行Java Jar as Service

我需要在Ubuntu EC2主机上通过ansible运行metabase.jar。

我应该守护它吗?有没有推荐的方法或库?

理想情况下,如果可能的话,我想通过Ansible处理程序管理状态。

感谢

回答

4

根据您的底层箱的初始系统(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 

更多信息:Ansible systemd module documentation

+1

的感谢!将尝试! – RedRobot

+0

尽管服务文件必须放在''/ etc/systemd/system'''中,否则正确 – RedRobot

+0

更改了我的答案中的路径。太棒了,它为你工作。 –