Categories
ThinkingSphinx Capistrano tasks
Pat Allan recently released some helpful capistrano tasks you can use to make it easier to deploy your rails apps which use Sphinx and ThinkingSphinx. These simplify the steps from my previous post about this so I’ve also included an update to my deployment setup.
ThinkingSphinx Capistrano Tasks
Each of these currently gets run in your production environment except for the thinking_sphinx:install tasks. I’m sure a patch would be welcome to make this work across any environment.
cap thinking_sphinx:configure |
Generate the Sphinx configuration file. |
cap thinking_sphinx:index |
Index data. |
cap thinking_sphinx:install:sphinx |
Install Sphinx by source. This currently grabs the current stable version of Sphinx and compiles it. |
cap thinking_sphinx:install:ts |
Install Thinking Sphinx as a gem from GitHub. If you have the plugin installed, there’s no need to do this. |
cap thinking_sphinx:rebuild |
Stop, re-index and then start the Sphinx daemon. |
cap thinking_sphinx:restart |
Stop and then start the Sphinx daemon. |
cap thinking_sphinx:shared_sphinx_folder |
Add the shared folder for sphinx for Sphinx files for the production environment. More on this below. |
cap thinking_sphinx:start |
Start the Sphinx daemon |
cap thinking_sphinx:stop |
Stop the Sphinx daemon |
Adding the new Capistrano tasks to your Rails app
If you’re using the Plugin, you don’t have to do anything as they should be loaded automatically for you. If you have any problems deploying, make sure your Capfile is up-to-date.
If you’re using the Gem add this to the top of your config/deploy.rb file:
require 'thinking_sphinx/deploy/capistrano
For either plugin or gem, add the following line at the bottom of the file:
after "deploy:setup", "thinking_sphinx:shared_sphinx_folder"
Using ‘cap thinking_sphinx:shared_sphinx_folder’
I have not personally run across any issues using symlinks, but some people have. Plus, using a symlink can make you go through extra steps during deployment. Now, there’s a new setting you can add to your config/sphinx.yml file to specify the full path to your Sphinx database files like so:
production: searchd_file_path: "/path/to/your/app/db/sphinx/production/"
This path will get automatically created if it does not exist.
Updated Method of Deploying a Rails app with ThinkingSphinx
Having a constant path to the Sphinx indexes means you really don’t have to do anything special on deployment assuming it’s already running. If your define_index block in any models are changing frequently, you can add a few lines so you don’t forget about re-indexing. Check out my revised deploy.rb file for details.
Updated deploy.rb file
My updated sample deploy.rb is pastied.
