简体   繁体   English

在Ubuntu上通过Ansible将Java Jar作为服务运行

[英]Run Java Jar as Service via Ansible on Ubuntu

What is the best approach to run a standalone .jar as a service via Ansible? 通过Ansible将独立的.jar作为服务运行的最佳方法是什么?

I need run metabase.jar via ansible on an Ubuntu EC2 host. 我需要在Ubuntu EC2主机上通过ansible运行metabase.jar。

Should I daemonize it? 我应该守护它吗? Is there any recommended method or library? 有没有推荐的方法或库?

Ideally I would like to manage the state via the Ansible handlers if possible. 理想情况下,如果可能的话,我想通过Ansible处理程序来管理状态。

Thanks 谢谢

Depending upon the init system of your underlying box (init.d or systemctl) there are two approaches. 取决于基础框(init.d或systemctl)的初始化系统,有两种方法。


init.d init.d中

With ansible you can create a symlink of your application jar under 使用ansible,您可以在下面创建应用程序jar的符号链接

/etc/init.d/<your_service_name>

You can then use ansible's service module to manage the state of the service 然后,您可以使用Ansible的服务模块来管理服务状态

 - service:
    name: <your_service_name>
    state: restarted

More info: Ansible service module documentation 更多信息: Ansible服务模块文档


systemctl systemctl

If your init method is systemd you will have to create a very simple Unit file 如果您的init方法是systemd,则必须创建一个非常简单的Unit文件

[Unit]
Description=<Description>

[Service]
ExecStart=/path/to/<your_app>.jar

[Install]
WantedBy=multi-user.target

Copy the unit file to 将单位文件复制到

/etc/systemd/service/<your_unit_file>.service

Then you can use ansible's systemd module to manage the state of the service 然后,您可以使用Ansible的systemd模块来管理服务状态

- name: Start Service
  systemd:
    name: <your service name>
    state: started

More info: Ansible systemd module documentation 更多信息: Ansible systemd模块文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM