我在一台服务器上运行了2个Rails应用程序。环境是Rails 4.0.0,Ruby 2,NGINX,unicorn,capistrano。
当我使用cap:deploy时,服务器将缓存并继续提供旧表单,直到重新启动。
重新启动时,其中一个应用程序将无法重新启动。我得到nginx服务的错误500。我需要在成功之前至少运行两次/etc/init.d/unicorn_myapp2重启并且服务器将再次运行。另一个应用程序具有相同的配置,但在重新启动后立即启动。
deploy.rb:
require "bundler/capistrano"
set :user, 'mark'
set :scm_passphrase, 'horrocks'
set :domain, '123.45.678.999'
set :application, "myapp_2"
set :repository, "#{user}@#{domain}:git/#{application}.git"
ssh_options[:forward_agent] = true
set :deploy_to, "/var/www/#{application}"
role :app, domain
role :web, domain
role :db, domain, :primary => true
default_run_options[:pty] = true
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
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