我对我的部署策略有点困惑,部署时在什么情况下我想发送 reload 向独角兽发出信号?例如,就我而言,它会是这样的:

sudo kill -s USR2 `cat /home/deploy/apps/my_app/current/tmp/pids/unicorn.pid`

我一直在通过杀死那个 pid 来部署我的应用程序,然后通过以下方式再次启动独角兽:

bundle exec unicorn -c config/unicorn/production.rb -E production -D

我只是想知道为什么我要使用重新加载?通过这样做,我的部署可以获得任何性能吗?

有帮助吗?

解决方案

当你杀死独角兽时,你会导致停机,直到独角兽可以重新启动。当您使用 USR2 信号时,unicorn 首先启动新的工人,然后一旦他们运行,它就会杀死旧的工人。这基本上都是为了消除“关闭”独角兽的需要。

请注意,假设您有记录的 before_fork 在你的unicorn配置中挂钩,为了处理旧worker的杀死,应该找到一个“.oldbin”文件,其中包含旧unicorn进程的PID:

before_fork do |server, worker|
  # a .oldbin file exists if unicorn was gracefully restarted with a USR2 signal
  # we should terminate the old process now that we're up and running
  old_pid = "#{pids_dir}/unicorn.pid.oldbin"
  if File.exists?(old_pid)
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # someone else did our job for us
    end
  end
end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top