Unicorn 在 USR2 和 QUIT 发出信号后下降几秒钟(不应该)

Unicorn downs for few seconds after USR2 and QUIT signals (Should not)

我有一个非常基本的独角兽应用程序。 Rails 5.1 应用程序 echos/prints "Hello World"。对于测试,我给了 4 个工人。

unicorn.rb:

worker_processes 4
preload_app true

timeout 30
listen '127.0.0.1:3000', :tcp_nopush => true, :backlog => 4096
# Logging
...

现在,我向主进程发送 USR2 信号。主进程成功接收到我的信号并创建了另一个主进程然后将其标记为“old”并将 PID 写入 oldbin 文件

问题从这里开始。当我确定第二个主人和他们的孩子已经创建时,我将 QUIT 发送给 old 主人。问题就在这里。当老主子收到QUIT,整个新老主子都掉线re-created。这会使我的系统停机几秒钟。

基本上,新主杀自己然后re-create。为什么?我在这里做错了什么?我认为这是零停机时间。我可以向你保证我有 3-5 秒的停机时间。

我检查过,老主人创建新主人,PID 5(例如),他们的孩子为 6、7、8、9。当我退出旧主人时,新主人变成 10 和工人变成 11,12,13,14。简单说明新旧都退出,重新re-created.

我不使用-D命令。我使用工头生成 systemd 文件,它是这样的:

[Unit]
PartOf=bp-web.target

[Service]
User=Pratha
WorkingDirectory=/var/www/app/releases/20170628140005
Environment=PORT=%i
ExecStart=/bin/bash -lc 'exec bundle exec unicorn -E production -c config/unicorn.rb'
Restart=always
StandardInput=null
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=%n
KillMode=mixed
TimeoutStopSec=5
  1. 我将 capistrano 用于 release-cycle 和部署。
  2. 如果我将 puma 与线程一起使用(甚至 16 个工作线程 50 个线程),我就会变得真实 "zero downtime"。

这是预期的行为:

Supervisord requires the unicorn process to not daemonize. Also sending SIGUSR2 to unicorn causes the old master to die. Since supervisord watches the old master this will cause it to consider the application as exited, even tho it's running with a new process id. Finally Supervisor will try to restart the application, and fail to do so because all sockets are in use by the new unicorn master.

解决方案:

  1. 要么使用 -D 选项并在没有 systemd/supervisord 的情况下自行启动你的独角兽 rails 应用程序。然后USR2就可以了。
  2. 或者使用 unicornherder 作为包装器。这将为您完成这项工作。没有停机时间。

参见link:Unicorn + Systemd/Supervisord & Zero Downtime = unicornherder