使用ansible在远程主机上启动长时间运行的进程

使用ansible在远程主机上启动长时间运行的进程,ansible,Ansible,我对Ansible不熟悉。我正在尝试使用一个非常简单的Ansible剧本在远程主机上启动一个进程 这是我的剧本的样子 - hosts: somehost gather_facts: no user: ubuntu tasks: - name: change directory and run jetty server shell: cd /home/ubuntu/code; nohup ./run.sh async: 45 sh使用

我对Ansible不熟悉。我正在尝试使用一个非常简单的Ansible剧本在远程主机上启动一个进程

这是我的剧本的样子

-
  hosts: somehost
  gather_facts: no
  user:  ubuntu  
  tasks:
    - name: change directory and run jetty server
      shell: cd /home/ubuntu/code; nohup ./run.sh    
      async: 45
sh使用几个参数调用java服务器进程。 我的理解是,在远程机器上使用异步我的进程将继续运行,即使在playbook完成之后(大约45秒后)

但是,一旦playbook退出,远程主机终端上的run.sh也会启动进程

谁能解释一下发生了什么,我错过了什么


谢谢

给异步一个更长的时间,比如说6个月、一年甚至更长的时间,这样应该可以。 或者将此进程转换为initscript并使用服务模块


再加上投票:0

我同意。因为它运行时间很长,所以我将它称为服务,并像这样运行它。只需创建一个init.d脚本,用“copy”将其推出,然后运行服务

我有ansible playbook来部署我的Play应用程序。我使用shell的命令替换来实现这一点,它为我做到了这一点。我认为这是因为命令替换产生了一个新的子shell实例来执行命令

-
  hosts: somehost
  gather_facts: no
  user:  ubuntu  
  tasks:
    - name: change directory and run jetty server
      shell: dummy=$(nohup /run.sh &) chdir={{/home/ubuntu/code}}