当升级ruby版本和puma时,Capistrano重新启动错误版本的puma

时间:2016-05-10 21:10:12

标签: capistrano puma

我正在升级一个Rails应用程序,部署有capistrano并运行puma,从ruby 2.2.0 / puma 3.2到ruby 2.3.1 / puma 3.4。当我部署puma似乎是在错误的版本中重新启动。

在部署之前,Puma正在pid 4717 / 3.4版本下运行

vagrant@vagrant-master:/mnt/code/shared/tmp/pids$ ps -ef | grep -i puma
vagrant   4717     1  0 20:53 ?        00:00:00 puma 3.4.0 (unix:///mnt/code/shared/tmp/sockets/code-puma.sock) [20160510205039]                                                                                                                                                                                                                                                        
vagrant   4720  4717 12 20:53 ?        00:00:10 puma: cluster worker 0: 4717 [20160510205039]            

当我部署旧版本(puma 3.2 / Ruby 2.2.0)时,puma重新启动,它现在在pid 5466下运行:

vagrant@vagrant-master:/mnt/code/shared/tmp/pids$ ps -ef | grep -i puma
vagrant   5466     1  0 20:56 ?        00:00:00 puma 3.4.0 (unix:///mnt/code/shared/tmp/sockets/code-puma.sock) [20160510205440]                                                                                                                                                                                                                                                        
vagrant   6154  5466  0 20:56 ?        00:00:00 puma: cluster worker 0: 5466 [20160510205440]     

我的puma错误日志显示其运行2.3.1而不是2.2.0

/usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/spec_set.rb:95:
in `block in materialize': Could not find active_attr-0.8.5 in any of the sources (Bundler::GemNotFound)

但是,应该切换到Puma 3.2 / ruby​​ 2.2.0。当我强行杀死美洲狮时,它会以正确的版本重启(通过monit)(在这种情况下为Puma 3.2)

vagrant@vagrant-master:/mnt/code/shared/tmp/pids$ kill -9 5466

vagrant@vagrant-master:/mnt/code/shared/tmp/pids$ ps -ef | grep -i puma
vagrant  17834     1  0 21:04 ?        00:00:00 puma 3.2.0 (unix:///mnt/code/shared/tmp/sockets/code-puma.sock) [20160510205440]                                                                                                                                                                                                                                                        
vagrant  17837 17834 90 21:04 ?        00:00:01 puma: cluster worker 0: 17834 [20160510205440]   

部署日志中的相关行:

DEBUG [07f95004] Running /usr/bin/env [ -f /mnt/code/shared/tmp/pids/puma.pid ] as vagrant@vagrant-master
DEBUG [07f95004] Command: [ -f /mnt/code/shared/tmp/pids/puma.pid ]
DEBUG [07f95004] Finished in 0.007 seconds with exit status 0 (successful).

DEBUG [42d98483] Running /usr/bin/env kill -0 $( cat /mnt/code/shared/tmp/pids/puma.pid ) as vagrant@vagrant-master
DEBUG [42d98483] Command: kill -0 $( cat /mnt/code/shared/tmp/pids/puma.pid )
DEBUG [42d98483] Finished in 0.007 seconds with exit status 0 (successful).

INFO [e81875a3] Running RBENV_ROOT=/usr/local/rbenv RBENV_VERSION=2.2.0 /usr/local/rbenv/bin/rbenv exec bundle exec pumactl -S /mnt/code/shared/tmp/pids/puma.state restart as vagrant@vagrant-master
DEBUG [e81875a3] Command: cd /mnt/code/current && ( export PATH="/usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH" RBENV_ROOT="/usr/local/rbenv" RBENV_VERSION="2.2.0" RACK_ENV="vagrant" ; RBENV_ROOT=/usr/local/rbenv RBENV_VERSION=2.2.0 /usr/local/rbenv/bin/rbenv exec bundle exec pumactl -S /mnt/code/shared/tmp/pids/puma.state restart )
DEBUG [e81875a3]    Command restart sent success

这是我在capistrano中的puma配置的一部分

set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_preload_app, false
set :puma_prune_bundler, true

如何在不必杀死美洲狮进程的情况下部署ruby-version和puma-version更改?为什么puma从错误的版本开始?

由于

1 个答案:

答案 0 :(得分:0)

检查puma.rb配置文件是否指定puma.pidpuma.state路径:

pidfile '/mnt/code/shared/tmp/pids/puma.pid'
state_path '/mnt/code/shared/tmp/pids/puma.state'

同时检查deploy/production.rb是否指定了以下路径:

set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"

我遇到了类似的问题,设置完成后效果很好。