Deploying Thinking Sphinx with Capistrano.

I’ve had a lot of issues trying to deploy ThinkingSphinx with Capistrano. This has been for a multitude of reasons. The following is my recipe for deploying and hopefully making it public will make a few peoples lives easier.

This assumes you are using the plugin, not the gem.

In your deploy.rb, add the following at the top:

require 'vendor/plugins/thinking-sphinx/lib/thinking_sphinx/deploy/capistrano'

Then, at the bottom add this:

before "deploy:rollback:revision",  "thinking_sphinx:stop_gracefully"
after  "deploy:default",            "thinking_sphinx:symlink"
after  "deploy:default",            "thinking_sphinx:ready"

namespace :thinking_sphinx do
task :stop_gracefully do
begin
thinking_sphinx.stop
rescue
puts "ThinkingSphinx is not running. No stop required."
end
end

desc "Configure, Index and then run Thinking Sphinx"
task :ready do
thinking_sphinx.configure
thinking_sphinx.index
thinking_sphinx.start
end

desc "Link up Sphinx's indexes."
task :symlink do
run "ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx"
end
end