Ruby on rails Unicorn仍指向旧版本文件夹

Ruby on rails Unicorn仍指向旧版本文件夹,ruby-on-rails,ruby,unix,capistrano,unicorn,Ruby On Rails,Ruby,Unix,Capistrano,Unicorn,我拥有一个Rails应用程序,使用Unicorn作为Web服务器 我通过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/#{applicatio

我拥有一个Rails应用程序,使用Unicorn作为Web服务器

我通过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, "git@github.com: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
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
部署顺利,服务器上的当前文件夹按预期包含更新的文件

但是,发生了一些我不理解的非常奇怪的事情:

在我的流程开始时,我有一句话:

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
文件:

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, "git@github.com: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
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

我发现问题出在哪里

事实上,Unicorn和Sidekiq之间存在故障排除

事实上,正如我在上面的一条评论中所说,这个过程是由Sidekiq发起的

首先,在deploy.rb中,必须有以下行:

require 'sidekiq/capistrano' 
这允许部署过程优雅地重新启动Sidekiq。 见:

其次,在unicorn.rb中,必须有这样的块:

after_fork do |server, worker|
  Sidekiq.configure_client do |config|
    config.redis = { :size => 1 }
  end
end
有关它的更多信息,请参见:

现在,没有更奇怪的问题:)

一个可能的解释是:


可能Sidekiq管理一些缓存,防止它基于上一版本…这就是为什么重新启动加上干净地启动Unicorn和Sidekiq就足够了。

请发布您的
config/Unicorn.rb
@iblue我想知道,进程在后台使用redis服务器。也许这一个有一种缓存。。。我要重新开始……你说的“我在我的流程开始时就有这一行”到底是什么意思。您将包含Logger.new的语句放在哪里了?哪个文件?什么时候启动?@iblue实际上这个过程代表一个作业任务。此作业任务通过以下行推送到Sidekiq(线程工作者管理器):job.find(id).run。“run”方法在一开始就包含一行:logger.info“start processing”。这个“logger”实际上是一个方法(是的,也是一个名为“logger”的方法),这个方法的第一行是:logger=logger.new“#{Rails.root}/log/web_agents.log”@iblue我刚刚重新启动了Redis服务器,仍然有相同的错误。。。