puma start 导致 "There is already a server bound to: <socket>" 错误

puma start causes "There is already a server bound to: <socket>" error

我无法可靠地重现这个问题,所以我将描述正在发生的事情,希望你们中的一位聪明的 puma 孩子能帮助我。

我总是在部署过程结束时停止并启动 puma。我 运行 pumactl -F <config_path> stop 有效,然后是命令 puma -q -d -e staging -C <config_path>,有时(并非总是)导致以下错误:

[12802] Puma starting in cluster mode... 
[12802] * Version 2.11.3 (ruby 2.1.2-p95), codename: Intrepid Squirrel
[12802] * Min threads: 2, max threads: 4
[12802] * Environment: staging
[12802] * Process workers: 2
[12802] * Phased restart available 
[12802] * Listening on unix:///<app_dir>/tmp/puma/sockets/puma.sock 
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/binder.rb:284:in `add_unix_listener': There is already a server bound to: <app_dir>/tmp/puma/sockets/puma.sock (RuntimeError)
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/binder.rb:124:in `block in parse'
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/binder.rb:82:in `each'
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/binder.rb:82:in `parse'
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/cluster.rb:325:in `run'
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/cli.rb:216:in `run'
<ruby_path>/2.1.0/gems/puma-2.11.3/bin/puma:10:in `<top (required)>'
<ruby_path>/2.1.0/bin/puma:23:in `load'
<ruby_path>/2.1.0/bin/puma:23:in `<main>'

如果我之后再次尝试 运行 相同的 puma start 命令,它会起作用。

这是我的 puma 配置:

#!/usr/bin/env puma

directory "<app_dir>/current"
rackup "<app_dir>/current/config.ru"
environment "staging"

pidfile "<app_dir>/tmp/puma/pid"
state_path "<app_dir>/tmp/puma/state"
activate_control_app "<app_dir>/tmp/puma/sockets/pumactl.sock"

stdout_redirect "<app_dir>/shared/log/puma.error.log", "<app_dir>/shared/log/puma.access.log", true

threads 2,4

bind "unix:///<app_dir>/tmp/puma/sockets/puma.sock"

workers 2

我的问题:

  1. 如何重现此错误?
  2. 我该如何解决?这是 puma 的问题还是我的配置问题?

而不是 运行 这两个命令...

pumactl -F <config_path> stop
puma -q -d -e <env> -C <config_path>

只需使用重启命令:

pumactl -F <config_path> restart

说明

puma README 中有一节关于 Restarting 的内容没有提及依次调用停止和启动命令。由于该用例不受支持,使用已建立的方法 restart puma 服务器很可能会解决此问题。

备注

我无法始终如一地重现此 puma 错误,因此我无法 100% 确认使用 pumactl restart 可以解决问题。 (尽管 puma 不支持 pumactl stop 后跟 puma 暗示它支持。)如果有人在使用支持的 pumactl restart 时仍然遇到此问题,请告诉我,以便我可以修改此答案。