应用程序尝试加载旧版本

时间:2014-01-16 14:06:58

标签: ruby-on-rails deployment ruby-on-rails-3.2 capistrano

当我尝试将我的应用程序的新版本部署到服务器时,在部署之后,我在域上只有我的应用程序的旧版本(在许多'cap deploy'之后它总是相同的),但当前目录在服务器具有最新版本的文件。
这是我的deploy.rb

require 'rvm/capistrano'
require 'bundler/capistrano'
require 'whenever/capistrano' 

set :port, 123456
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user
set :user, "username"

ssh_options[:forward_agent] = true
set :deploy_via, :remote_cache
default_run_options[:pty] = true
set :application, "app_name"
set :rails_env, "production"
server "server.com", :app, :web, :db, primary: true
set :deploy_to, "/home/user/#{application}"
set :use_sudo, false
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
set :keep_releases, 3
set :scm, :git
set :repository,  "rep_name"
set :whenever_command, "bundle exec whenever"
set :branch, "master"
load 'deploy/assets'

before "deploy:setup", "db:configure"
before  "deploy:assets:precompile", "db:symlink"

namespace :db do
    desc "Create database yaml in shared path"
    ...   
    desc "Make symlink for database yaml"
    ...
end

namespace :deploy do
    task :create_release_dir, :except => {:no_release => true} do
        run "mkdir -p #{fetch :releases_path}"
    end
    task :restart do
        run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn_rails -c #{unicorn_conf} -E #{rails_env} -D; fi"
    end
    task :start do
        run "bundle exec unicorn_rails -c #{unicorn_conf} -E #{rails_env} -D"
    end
    task :stop do
        run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
    end
end

这是我的unicorn.rb

deploy_to  = "/home/user/app_name"
rails_root = "#{deploy_to}/current"
pid_file   = "#{deploy_to}/shared/pids/unicorn.pid"
socket_file= "#{deploy_to}/shared/unicorn.sock"
log_file   = "#{rails_root}/log/unicorn.log"
err_log    = "#{rails_root}/log/unicorn_error.log"
old_pid    = pid_file + '.oldbin'

timeout 30
worker_processes 4 
listen socket_file, :backlog => 1024
pid pid_file
stderr_path err_log
stdout_path log_file

preload_app true 

GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) 

before_exec do |server|
  ENV["BUNDLE_GEMFILE"] = "#{rails_root}/Gemfile"
end

before_fork do |server, worker|
  defined?(ActiveRecord::Base) and
  ActiveRecord::Base.connection.disconnect!

  if File.exists?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
end

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and
  ActiveRecord::Base.establish_connection
end

1 个答案:

答案 0 :(得分:0)

当unicorn无法正常重启时会发生这种情况。尝试停止服务器然后启动服务器。您应该在启动时收到错误,然后检查unicorn.errror.log文件以获取错误信息。