我在生产环境中有一个 Rails 3.1 项目。
现在这是我的 deploy.rb:
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load pathe
require "rvm/capistrano" # Load RVM's capistrano plugin.
require "bundler/capistrano"
set :rvm_ruby_string, 'ruby-1.9.2-p318@global'
set :rvm_type, :user
set :application, "domain.com"
set :user, 'user'
#set :repository, "#{user}@ip.ip.ip.ip:~/app"
set :repository, "ssh://git@bitbucket.org/user/app.git"
set :keep_releases, 3
set :scm, :git
set :use_sudo, false
set :deploy_to, "~/#{application}"
#set :deploy_via, :copy
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
set :deploy_via, :remote_cache
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
role :web, "ip.ip.ip.ip" # Your HTTP server, Apache/etc
role :app, "ip.ip.ip.ip" # This may be the same as your `Web` server
role :db, "ip.ip.ip.ip", :primary => true # This is where Rails migrations will run
namespace :deploy do
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 -c #{unicorn_conf} -E #{rails_env} -D; fi"
end
task :start do
run "bundle exec unicorn -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
load 'deploy/assets'
after "deploy:restart", "deploy:cleanup"
我想在 Capistrano 中完成这些任务。现在我手动执行这些任务:
1º 我用以下方法杀死 sunspot solr pid:
a) 使用 ps aux | 查找 pid grep 'solr'
b) 使用 kill pid_number
杀死 pid
2º 删除生产环境中的索引 solr,如果存在:
a) rm -r solr/data/production/index
3º 打开太阳黑子 solr:
a) RAILS_ENV=production rake sunspot:solr:start
4º Reindex 模型:
a) RAILS_ENV=production rake sunspot:mongo:reindex
我的问题是:
如何将这些任务添加到我的 deploy.rb?
谢谢!
最佳答案
这可能是一个很好的起点:
namespace :solr do
task :reindex do
run "cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} sunspot:solr:reindex"
end
end
您可以只调用 rake sunspot:solr:stop
而不是 kill 吗?如果您要重新编制索引,我不确定是否需要删除索引...
关于ruby-on-rails-3 - 在 Rails 3.1 中使用 Capistrano 进行部署时重启 sunspot solr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9894014/