问题原文
原帖链接 · Ryan Grush · CC BY-SA 4.0
I have a playbook to install puma on my ec2 instance and everything is fine except when I run bundle exec pumactl start at the the end it starts the server but the playbook hangs indefinitely.
Here is the Ansible task -
- shell: /home/ubuntu/.rbenv/shims/bundle exec pumactl start
args:
chdir: /home/{{ user }}/{{ app_name }}
warn: no
Is there a way to avoid this?
Update
I added this to my /etc/systemd/system/puma.service file and ran it with systemd as @Michael suggested -
[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
已采纳解答
原帖链接 · Michael Hampton · CC BY-SA 4.0
You forgot to daemonize puma, so it's running in the foreground. Ansible has been waiting for it to exit. Add the -d option to the command.
Better yet, you should create a systemd unit to run puma as a service, and then start that service. Daemonizing is not required in that case, as systemd will handle everything.
BTW, it is best practice to use command instead of shell unless you actually need shell processing (which in this case you do not).
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
