[英]Capistrano-unicorn gem getting wrong environment set
我已經使用了一段時間了,只是潛入嘗試在我的登台服務器上部署實際的登台環境,但遇到了問題。 盡管所有設置都是正確的,但Unicorn從命令unicorn_rails
和-E production
開始。
我在deploy.rb中注意到,我的unicorn_bin變量設置為unicorn_rails。 我在deploy.rb中刪除了此設置。 然而麒麟:重復仍執行unicorn_rails
命令,當默認的應該是unicorn
。
正如多階段安裝Wiki文檔中概述的那樣,我的var全部都設置為deploy / staging.rb,但我注意到-E仍將投入生產。
相關信息:
這是部署后我的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)
這是cap -T
的輸出(默認為暫存)
# Environments
rails_env "staging"
unicorn_env "staging"
unicorn_rack_env "staging"
# Execution
unicorn_user nil
unicorn_bundle "/usr/local/rvm/gems/ruby-2.0.0-p247@global/bin/bundle"
unicorn_bin "unicorn"
unicorn_options ""
unicorn_restart_sleep_time 2
# Relative paths
app_subdir ""
unicorn_config_rel_path "config"
unicorn_config_filename "unicorn.rb"
unicorn_config_rel_file_path "config/unicorn.rb"
unicorn_config_stage_rel_file_path "config/unicorn/staging.rb"
# Absolute paths
app_path "/var/www/apps/myapp/current"
unicorn_pid "/var/www/apps/myapp/shared/pids/unicorn.myapp.pid"
bundle_gemfile "/var/www/apps/myapp/current/Gemfile"
unicorn_config_path "/var/www/apps/myapp/current/config"
unicorn_config_file_path "/var/www/apps/myapp/current/config/unicorn.rb"
unicorn_config_stage_file_path
-> "/var/www/apps/myapp/current/config/unicorn/staging.rb"
另一個奇怪的是,unicorn_rails -E標志應該引用rails環境,而unicorn -E應該引用機架環境-機架環境應該只獲取值的開發和部署,但是將其設置為生產,這有點奇怪( 有關RACK_ENV變量的設置,請參見unicorn文檔 。
任何對此的見解將不勝感激。 在登台服務器上,我還將RAILS_ENV設置為登台。 我已經為其他環境的Rails設置了東西,例如在我的環境文件夾中添加staging.rb,向database.yml添加一個staging部分,等等。
lib / capistrano-unicorn / config.rb中的重要行談論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
提前致謝。
好吧,很長一段時間沒有正確的環境后,我發現了這個問題!
基本上,我的初始化腳本是在我的capistrano-unicorn bin做它的事情之前運行的。
因此,在capistrano-unicorn執行unicorn重新啟動/重新加載/復制任務時,請確保將用於管理Unicorn及其工作程序的init.d或upstart腳本考慮在內。
當我不得不調試陳舊的pid文件/已經在運行/無法偵聽套接字錯誤時,我不認為要看這些腳本。 但這是有道理的,因為新貴會在不運行時啟動Unicorn,然后capistrano-unicorn也正嘗試啟動Unicorn。
現在,我將這些Capistrano任務和掛鈎與Monit和Unicorn初始化腳本結合在一起。
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
Capistrano掛鈎:
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監控我的獨角獸過程:
在/ 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在deploy.rb中具有使用:set
指令,可讓您指定該獨角獸進程的環境。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.