1 # Ferret DRb server Capistrano tasks
4 # in your Capfile, add acts_as_ferret's recipes directory to your load path and
5 # load the ferret tasks:
7 # load_paths << 'vendor/plugins/acts_as_ferret/recipes'
10 # This will hook aaf's DRb start/stop tasks into the standard
11 # deploy:{start|restart|stop} tasks so the server will be restarted along with
12 # the rest of your application.
13 # Also an index directory in the shared folder will be created and symlinked
14 # into current/ when you deploy.
16 # In order to use the ferret:index:rebuild task, declare the models you intend to
17 # index in config/deploy.rb:
19 # for a shared index, do:
20 # set :ferret_single_index_models, [ Model, AnotherModel, YetAnotherModel ]
21 # This will call Model.rebuild_index( AnotherModel, YetAnotherModel )
23 # for models indexed separately, specify:
24 # set :ferret_models, [ Model, AnotherModel ]
25 # This will call Model.rebuild_index and AnotherModel.rebuild_index separately.
27 # The two methods may be combined if you have a shared index, and some models
30 # Like to submit a patch to aaf? Automatically determining the models that use
31 # acts_as_ferret so the declaration of these variables in deploy.rb isn't
32 # necessary anymore would be really cool ;-)
35 # HINT: To be very sure that your DRb server and application are always using
36 # the same model and schema versions, and you never lose any index updates because
37 # of the DRb server being restarted in that moment, use the following sequence
38 # to update your application:
40 # cap deploy:stop deploy:update deploy:migrate deploy:start
42 # That will stop the DRb server after stopping your application, and bring it
43 # up before starting the application again. Plus they'll never use different
44 # versions of model classes (which might happen otherwise)
45 # Downside: Your downtime is a bit longer than with the usual deploy, so be sure to
46 # put up some maintenance page for the meantime.
50 desc "Stop the Ferret DRb server"
51 task :stop, :roles => :app do
52 run "cd #{current_path}; script/ferret_server -e #{rails_env} stop"
55 desc "Start the Ferret DRb server"
56 task :start, :roles => :app do
57 run "cd #{current_path}; script/ferret_server -e #{rails_env} start"
60 desc "Restart the Ferret DRb server"
61 task :restart, :roles => :app do
69 desc "Rebuild the Ferret index. See aaf_recipes.rb for instructions."
70 task :rebuild, :roles => :app do
71 rake = fetch(:rake, 'rake')
72 single_index_models = fetch(:ferret_single_index_models, nil)
73 if single_index_models
74 run "cd #{current_path}; RAILS_ENV=#{rails_env} MODEL='#{ferret_single_index_models.join(' ')}' #{rake} ferret:rebuild"
76 fetch(:ferret_models, []).each do |m|
77 run "cd #{current_path}; RAILS_ENV=#{rails_env} MODEL='#{m}' #{rake} ferret:rebuild"
81 desc "purges all indexes for the current environment"
82 task :purge, :roles => :app do
83 run "rm -fr #{shared_path}/index/#{rails_env}"
86 desc "symlinks index folder"
87 task :symlink, :roles => :app do
88 run "mkdir -p #{shared_path}/index && rm -rf #{release_path}/index && ln -nfs #{shared_path}/index #{release_path}/index"
95 after "deploy:stop", "ferret:stop"
96 before "deploy:start", "ferret:start"
98 before "deploy:restart", "ferret:stop"
99 after "deploy:restart", "ferret:start"
100 after "deploy:symlink", "ferret:index:symlink"