カピストラーノを使用して、既存の ROR アプリケーションにいくつかの変更をデプロイしようとしています。MAC OSX を実行しており、サーバーは Ubuntu 12.0.4 です。私は ROR と capistrano を初めて使用するので、これまでに行ったことの概要を以下に示します。github リポジトリをローカル フォルダーに複製し、コードを変更し、github リポジトリを更新し、次を使用して capistrano をインストールしました: を使用してgem install capistrano
、ターミナルを開き、ディレクトリを ROR アプリがあるローカル フォルダーに変更し、 を試しcap deploy:check
ました。プロジェクトには既存の Deploy および Cap ファイルがあるため、プロジェクトをキャプションしませんでした。実行するcap deploy:check
と、次の出力が得られます。
/Users/ben/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- delayed/recipes (LoadError)
from /Users/ben/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:152:in `require'
from ./config/deploy.rb:2:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:93:in `instance_eval'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:93:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:172:in `load_from_file'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:89:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `block in load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `each'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `load'
from Capfile:4:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:93:in `instance_eval'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:93:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:172:in `load_from_file'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:89:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `block in load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `each'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:86:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:65:in `block in load_recipes'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:65:in `each'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:65:in `load_recipes'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:31:in `execute!'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/lib/capistrano/cli/execute.rb:14:in `execute'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/gems/capistrano-2.15.4/bin/cap:4:in `<top (required)>'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/bin/cap:19:in `load'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/bin/cap:19:in `<main>'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@myapp/bin/ruby_noexec_wrapper:14:in `<main>'
これが私の deploy.rb ファイルのサンプルです (ユーザー名、サーバー名などを編集したもの)。
require "bundler/capistrano"
require "delayed/recipes"
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"") # Read from local system
require 'rvm/capistrano'
set :rails_env, "production" #added for delayed job
server "myservername", :web, :app, :db, primary: true
set :application, "myapp"
set :user, "deploy"
set :deploy_to, "/home/#{user}/apps/#{application}"
#set :deploy_via, :remote_cache
set :use_sudo, false
set :shared_children, shared_children + %w{public/uploads}
set :scm, "git"
set :scm_passphrase, "mypassword"
set :repository, "git@github.com:myusername/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart"
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.example.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
namespace :mailman do
desc "Mailman::Start"
task :start, :roles => [:app] do
run "cd #{current_path};RAILS_ENV=#{rack_env} bundle exec script/mailman_daemon start"
end
desc "Mailman::Stop"
task :stop, :roles => [:app] do
run "cd #{current_path};RAILS_ENV=#{rack_env} bundle exec script/mailman_daemon stop"
end
desc "Mailman::Restart"
task :restart, :roles => [:app] do
mailman.stop
mailman.start
end
end
そして、これが cap ファイルのコピーです。
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks
これについて何か助けていただければ幸いです。実稼働環境にいくつかの変更をデプロイする必要があるだけですが、今はまだ立ち往生しています。うまくいけば、私は十分な情報を提供しました。ただし、cap と ruby にまったく慣れていないので、明らかなことを見落としている可能性があります。前もって感謝します!