【发布时间】:2012-01-26 19:57:14
【问题描述】:
我的 deploy.rb 中有以下任务
namespace :unicorn do
desc "stop unicorn"
task :stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill `cat #{unicorn_pid}`"
end
desc "start unicorn"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} unicorn -c #{current_path}/config/unicorn.rb -E #{rails_env} -D"
end
task :reload, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
end
after "deploy:restart", "unicorn:reload"
end
当我从我的开发机器上运行 unicorn:start 或 unicorn:reload 任务时,服务器上的一切看起来都很好:
$ ps aux | grep unicorn
myuser 8196 77.9 12.2 81020 62748 ? Sl 19:18 0:14 unicorn master -c /home/myuser/www/myapp/current/config/unicorn.rb -E production -D
myuser 8216 0.0 11.5 81020 59232 ? Sl 19:18 0:00 unicorn worker[0] -c /home/myuser/www/myapp/current/config/unicorn.rb -E production -D
但是,当我运行完整的 cap deploy 时,我得到了 unicorn 服务器的多个实例,这让 nginx 感到非常困惑。
$ ps aux | grep unicorn
myuser 8196 4.4 12.2 81020 62764 ? Sl 19:18 0:14 unicorn master (old) -c /home/myuser/www/myapp/current/config/unicorn.rb -E production -D
myuser 8216 1.1 13.2 87868 67764 ? Sl 19:18 0:03 unicorn worker[0] -c /home/myuser/www/myapp/current/config/unicorn.rb -E production -D
myuser 8362 5.8 12.8 83448 65408 ? Sl 19:19 0:16 unicorn master -c /home/myuser/www/myapp/current/config/unicorn.rb -E production -D
myuser 8385 0.0 12.1 83712 61980 ? Sl 19:19 0:00 unicorn worker[0] -c /home/myuser/www/myapp/current/config/unicorn.rb -E production -D
我不知道为什么 unicorn:reload 在部署时会启动这些重复的实例。显然它并没有阻止以前的主人/工人。我必须运行两次 unicorn:stop 任务,然后再次运行 unicorn:start 以纠正问题
还有其他人遇到这个吗?我一直在戳它几个小时没有任何运气
【问题讨论】:
-
好的,我刚刚注意到一些可疑的东西。当我运行重新加载任务时,另一个进程被添加到混合中(并且我的 pid 文件已更新)为了便于阅读,您可以在此处查看它:pastie.textmate.org/3258997 当我运行时此进程不存在 unicorn:start,只有 unicorn:reload。我认为这是罪魁祸首,因为 pid 文件发生了变化,并且 kill 命令不再能够关闭主独角兽。该死的,我离得太近了!可能只需要睡在这个上面。
标签: capistrano unicorn