2014-01-16 72 views
2

當我嘗試將新版本的應用程序部署到服務器時,在部署之後,我的域名上只有我的應用程序的舊版本(它經常是相同的,經過許多cap部署) ,但服務器上的當前目錄具有最新版本的文件。
這是我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 
+0

發佈你的'config/unicorn.rb'配置文件。 pidfile應該在那裏設置,否則它將不會被寫入。 – rewritten

+0

@rewritten,完成。 – kamsharipova

+0

獨角獸無法正常重新啓動時會出現這種情況。嘗試停止服務器,然後啓動服務器。你應該在啓動時出錯,然後檢查你的unicorn.errror.log文件是否有錯誤信息。 – itsnikolay

回答

0

這發生在麒麟不能正確地重新啓動。嘗試停止服務器,然後啓動服務器。你應該在啓動時出錯,然後檢查你的unicorn.errror.log文件是否有錯誤信息。

相關問題