Ansible 在 pumactl start 时挂起

Ansible 在 pumactl start 时挂起

我有一个剧本,用于在我的 ec2 实例上安装 puma,一切都很好,除了当我bundle exec pumactl start在最后运行时它启动了服务器,但剧本无限期地挂起。

这是 Ansible 任务 -

 - shell: /home/ubuntu/.rbenv/shims/bundle exec pumactl start
   args: 
     chdir: /home/{{ user }}/{{ app_name }}
     warn: no

有办法避免这种情况吗?

更新

我将其添加到我的/etc/systemd/system/puma.service文件中,并按照@Michael的建议使用systemd运行它-

[Unit]
Description=Puma Rails Server
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/my_app
ExecStart=/bin/bash -lc '/home/ubuntu/.rbenv/shims/bundle exec puma -C /home/ubuntu/my_app/config/puma.rb'
ExecStop=/bin/bash -lc '/home/ubuntu/.rbenv/shims/bundle exec pumactl -S /home/ubuntu/my_app/shared/pids/puma.state stop'
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target

答案1

您忘记将 puma 设为守护进程,因此它在前台运行。Ansible 一直在等待它退出。将-d选项添加到命令中。

更好的是,你应该创建 systemd 单元以将 puma 作为服务运行, 进而启动该服务. 在这种情况下不需要守护进程,因为 systemd 将处理一切。

顺便说一句,最佳做法是使用commandshell不是,除非您实际上需要 shell 处理(在这种情况下您不需要)。

相关内容