Ruby on rails Capistrano独角兽宝石获得错误的环境设置

Ruby on rails Capistrano独角兽宝石获得错误的环境设置,ruby-on-rails,capistrano,unicorn,Ruby On Rails,Capistrano,Unicorn,我使用这个gem已经有一段时间了,只是尝试在我的登台服务器上部署一个实际的登台环境,但我遇到了一些问题。Unicorn从命令Unicorn_rails和-E production开始,尽管所有设置都是正确的 我在deploy.rb中注意到我的unicorn\u bin变量被设置为unicorn\u rails。我在deploy.rb中取出了这个设置。但是,unicorn:duplicate仍然执行unicorn_rails命令,而默认值应该是unicorn 我的VAR在deploy/stagin

我使用这个gem已经有一段时间了,只是尝试在我的登台服务器上部署一个实际的登台环境,但我遇到了一些问题。Unicorn从命令Unicorn_rails和-E production开始,尽管所有设置都是正确的

我在deploy.rb中注意到我的unicorn\u bin变量被设置为unicorn\u rails。我在deploy.rb中取出了这个设置。但是,unicorn:duplicate仍然执行unicorn_rails命令,而默认值应该是unicorn

我的VAR在deploy/staging.rb中都设置为staging,如多级设置wiki文档中所述,但我注意到-E仍然设置为production

相关信息:

以下是部署后我的unicorn.log文件的输出:

executing ["/var/www/apps/myapp/shared/bundle/ruby/2.0.0/bin/unicorn_rails", "-c", "/var/www/apps/bundio/current/config/unicorn.rb", "-E", "production", "-D", {12=>#<Kgio::UNIXServer:/tmp/bundio.socket>, 13=>#<Kgio::TCPServer:fd 13>}] (in /var/www/apps/bundio/current)
另一个有趣的是,unicorn_rails-E标志应该引用rails环境,而unicorn-E应该引用rack env——rack env应该只获取developement和deployment的值,但是它被设置为production,这有点奇怪

对此有任何见解都将不胜感激。在我的staging服务器上,我还将RAILS_ENV设置为staging。我已经为另一个环境的rails设置了一些东西,比如在我的environments文件夹中添加staging.rb,在database.yml中添加staging部分,等等

谈论unicorn_rack_env时的要点:

_cset(:unicorn_env)                { fetch(:rails_env, 'production' ) }
_cset(:unicorn_rack_env) do
# Following recommendations from http://unicorn.bogomips.org/unicorn_1.html
fetch(:rails_env) == 'development' ? 'development' : 'deployment'
end

提前谢谢。

好的,在长时间没有正确的环境之后,我发现了问题

基本上,我的init脚本是在capistrano unicorn bin运行之前运行的

因此,在capistrano Unicorn执行Unicorn重新启动/重新加载/复制任务时,请确保将用于管理Unicorn及其工作人员的init.d或upstart脚本考虑在内

当我不得不调试陈旧的pid文件/已经在运行/无法侦听套接字错误时,我没有想到要查看这些脚本。但这是有道理的,因为新贵在Unicorn不运行时启动了它,然后capistrano Unicorn也在尝试启动Unicorn

现在,我将这些capistrano任务和挂钩与Monit和Unicorn init脚本结合起来

Capistrano任务:

namespace :monit do
  desc ' wait 20 seconds '
  task :wait_20_seconds do
    sleep 20
  end
  task :monitor_all, :roles => :app do
    sudo "monit monitor all"
  end

  task :unmonitor_all, :roles => :app do
    sudo "monit unmonitor all"
  end

  desc 'monitor unicorn in the monit rc file'
  task :monitor_unicorn, :roles => :app do
    sudo "monit monitor unicorn"
  end

  desc 'unmonitor unicorn in the monit rc file'
  task :unmonitor_unicorn, :roles => :app do
    sudo "monit unmonitor unicorn"
  end
end
卡皮斯特拉诺钩子:

after 'deploy:restart', 'unicorn:duplicate'  # app preloaded. check https://github.com/sosedoff/capistrano-unicorn section for zero downtime

before 'deploy', "monit:unmonitor_unicorn"
before 'deploy:migrations', "monit:unmonitor_unicorn"

after 'deploy', 'monit:wait_20_seconds'
after "deploy:migrations", "monit:wait_20_seconds"

after 'monit:wait_20_seconds', 'monit:monitor_unicorn'
我使用Monit监视我的unicorn进程:

在/etc/monit/monitrc中:

check process unicorn
  with pidfile /var/www/apps/my_app/shared/pids/mypid.pid
  start program = "/usr/bin/sudo service unicorn start"
  stop program = "/usr/bin/sudo service unicorn stop"
在init脚本中,您将使用以下命令启动unicorn进程: unicorn_rails-c/var/www/apps/my_app/current/config/unicorn.rb-E staging-D 确保将-E标志设置为正确的环境。capistrano unicorn gem具有使用:set in deploy.rb的指令,该指令允许您指定unicorn进程的环境

check process unicorn
  with pidfile /var/www/apps/my_app/shared/pids/mypid.pid
  start program = "/usr/bin/sudo service unicorn start"
  stop program = "/usr/bin/sudo service unicorn stop"