0

我在一台服务器上运行了 2 个 Rails 应用程序。环境是 Rails 4.0.0、Ruby 2、NGINX、独角兽、capistrano。

当我使用 cap:deploy 时,服务器将缓存并继续提供旧表单,直到重新启动。

当我重新启动时,其中一个应用程序将不会重新启动。我收到 nginx 提供的错误 500。我需要运行 /etc/init.d/unicorn_myapp2 restart 至少两次才能成功,服务器将再次运行。另一个应用程序具有相同的配置,但在重新启动后立即启动。

部署.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
4

0 回答 0