2012-08-09 70 views
1

我擁有一個與Unicorn作爲Web服務器的Rails應用程序。獨角獸仍然指向舊的版本文件夾

我通過Capistrano部署它。

這裏我deploy.rb文件:

require "bundler/capistrano" 

server "91.121.11.100", :web, :app, :db, primary: true 

set :application, "myapp" 
set :user, "deployer" 
set :deploy_to, "/home/#{user}/apps/#{application}" 
#set :deploy_via, :remote_cache 
set :use_sudo, false 

set :scm, "git" 
set :repository, "[email protected]:therepository/#{application}.git" 
set :branch, "master" 

default_run_options[:pty] = true 
ssh_options[:forward_agent] = true 

#after "deploy", "deploy:cleanup" # keep only the last 5 releases 

namespace :deploy do 
    %w[start stop restart].each do |command| 
    desc "#{command} unicorn server" 
    task command, roles: :app, except: {no_release: true} do 
     run "/etc/init.d/unicorn_#{application} #{command}" 
    end 
    end 

    task :setup_config, roles: :app do 
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}" 
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}" 
    run "mkdir -p #{shared_path}/config" 
    put File.read("config/database.yml"), "#{shared_path}/config/database.yml" 
    puts "Now edit the config files in #{shared_path}." 
    end 
    after "deploy:setup", "deploy:setup_config" 

    task :symlink_config, roles: :app do 
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" 
    end 
    after "deploy:finalize_update", "deploy:symlink_config" 

    desc "Make sure local git is in sync with remote." 
    task :check_revision, roles: :web do 
    unless `git rev-parse HEAD` == `git rev-parse origin/master` 
     puts "WARNING: HEAD is not the same as origin/master" 
     puts "Run `git push` to sync changes." 
     exit 
    end 
    end 
    before "deploy", "deploy:check_revision" 
end 

部署以及發生與當前文件夾服務器包含更新的文件如預期。

不過,很奇怪的東西,我不明白髮生了:

我有這條線在我的進程的開始:

logger = Logger.new "#{Rails.root}/log/web_agents.log" 

,但此錯誤仍然出現:

No such file or directory - /home/deployer/apps/myapp/releases/20120612122610/log/web_agents.log 

爲什麼20120612122610 ???這是一箇舊版本,我甚至刪除了。

爲什麼Unicorn指向最後的版本?

爲了測試,我甚至用當前硬編碼路徑代替Rails.root。

還是得到了同樣的錯誤......我已經殺,停止強行停止麒麟......沒關係......

任何想法?

我確定,我確定使用'當前'文件夾中的上次更新文件啓動進程,因爲當我刪除進程時,進程無法工作並出現許多錯誤。

修訂

這裏我config/unicorn.rb文件:

root = "/home/deployer/apps/myapp/current" 
working_directory root 
pid "#{root}/tmp/pids/unicorn.pid" 
stderr_path "#{root}/log/unicorn.log" 
stdout_path "#{root}/log/unicorn.log" 

listen "/tmp/unicorn.myapp.sock" 
worker_processes 2 
timeout 30 
+0

請發佈您的'config/unicorn.rb' – iblue 2012-08-09 22:42:59

+0

@iblue unicorn.rb發佈。 – Mik378 2012-08-09 22:47:07

+0

@iblue我想知道一些事情,進程在後臺使用redis服務器。也許這個保留一種緩存...我要重新啓動它.. – Mik378 2012-08-09 22:48:54

回答

2

我發現自己哪裏出了問題的來源。

事實上,Unicorn和Sidekiq之間存在故障排除。

事實上,正如我在上面的一條評論中所說的,過程由Sidekiq發起。

首先,deploy.rb內,必須有這一行:

require 'sidekiq/capistrano' 

這使得部署過程平滑重啓Sidekiq。 請看那裏: https://github.com/mperham/sidekiq/wiki/Deployment

其次,在獨角獸。RB,必須有這種塊:

after_fork do |server, worker| 
    Sidekiq.configure_client do |config| 
    config.redis = { :size => 1 } 
    end 
end 

有關它的更多信息,請參見有:

https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting

而現在,沒有更多的奇怪的問題:)

一潛在的解釋:

可能Sidekiq管理一些緩存,防止它基於最後的rel緩解......這就是爲什麼重新啓動加上乾淨地啓動Unicorn和Sidekiq就足夠了。