kamsharipova
kamsharipova

Reputation: 23

Application trying to load old release

When I'm trying to deploy new version of my app to server, after deployment, I only have old version of my app on the domain (it always the same, after many 'cap deploy's), but the current directory on server has the last versions of files.
Here's my 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


Here's my 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

Upvotes: 2

Views: 175

Answers (1)

nikolayp
nikolayp

Reputation: 17919

This happens when unicorn can not be properly restarted. Try to stop server and then start server. You should get error on start, then check your unicorn.errror.log file for error information.

Upvotes: 1

Related Questions