Deploying a Rails app with Thinking Sphinx

Now that I'm using Thinking Sphinx I eventually had to deploy it. Since I didn't find much info about deploying it using Capistrano here's what I did to get deployments running smoothly.

If you're using or investigated full-text search options you've likely come across some really great comments about Sphinx. It's fast and has a lot of great features.

For a Rails application, there are a few plugins which make it easy to use Sphinx. The main two at this time are UltraSphinx and Thinking Sphinx. I chose Thinking Sphinx for my project mostly because it can keep the Sphinx indexes current in close to real-time as things are added to the database using delta indexes. UltraSphinx can use delta indexes, but doesn't seem to be as real-time at updating them as ThinkingSphinx. If I'm wrong, please correct me.

Now that I'm using Thinking Sphinx I eventually had to deploy it. Since I didn't find much info about deploying it using "Capistrano": here's what I did to get deployments running smoothly.

Sphinx Index Location

While Sphinx is fast, you still probably don't want to have to re-create your indexes on every deployment. I have my indexes getting created into my shared path and an :after_symlink task deals with making sure my app is pointing to the right place.

  desc "Re-establish symlinks"
  task :after_symlink do
    run <<-CMD
      rm -fr #{release_path}/db/sphinx &&
      ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx

Stopping and Starting Sphinx

Thinking Sphinx follows convention rather than configuration. Before any index Thinking Sphinx re-creates your configuration file based on the information in your models. Since it re-creates it, I have it ignored in my repository. As such, the configuration file does not exist on a fresh deploy.

I created some tasks to stop, start and restart Sphinx using the rake commands that come with Thinking Sphinx. One problem I ran into right away was the absence of the config/production.sphinx.conf file that's expected when you run the thinking_sphinx:start task. Luckily, there's another rake task called thinking_sphinx:configure which re-creates the configuration file without performing a full index.

While there is a thinkning_sphinx:restart task, that doesn't give me the opportunity to re-create the config file prior to starting Sphinx up again.

  desc "Stop the sphinx server"
  task :stop_sphinx , :roles => :app do
    run "cd #P15 && rake thinking_sphinx:stop RAILS_ENV=production"
  desc "Start the sphinx server" 
  task :start_sphinx, :roles => :app do
    run "cd #P15 && rake thinking_sphinx:configure RAILS_ENV=production && rake thinking_sphinx:start RAILS_ENV=production"
  desc "Restart the sphinx server"
  task :restart_sphinx, :roles => :app do

Restarting the App

Now that the Sphinx tasks are there, you just have to update the applications's :restart task to restart Sphinx when you restart your app.

  desc "Restart mongrel"
  task :restart, :roles => :app do
    sudo restart_mongrel

A full version of the example deploy.rb is pastied.

How to get a good designer to do something within your budget

I overheard someone talking about not being able to find a designer to help them with a web project for less than a certain hourly rate. It’s not the hourly rate that matters, it’s the overall cost.

Here are some tips for getting a good designer to help you out regardless of cost:

  • It’s who you know. You need to get out and meet with designers. In the Dallas area, Refresh Dallas is a good venue for this. Sometimes designers need development work, too, so maybe you can sync up on something. Especially if you’re around a big city, there will be a similar group.
  • Better yet, work with good designers. If you do good work, they’ll remember and want to work with you more and give you some slack on price when you need it. They’ll recommend you to others, too.
  • Tell them what you’ve got to spend up front. They’ll tell you what they can do. It’s possible all you need is a one page template and if you ask them to simply design a site, that typically entails much more effort. Some of the better designers I know ask for a budget outright so they know what they can offer within the constraints.
  • If they can’t be of service, ask if they know anyone who could. Designers often know other designers.

Stay back, IE7!

Inevitably, today on my Windows XP notebook, the automatic update finally told me that it wanted to install IE7. Since I still need IE6 to test with and have IE7 working quite nicely on my MacBookPro in Parallels, I’m not going there.

More Articles

Page 4 of 10 » ‹ First  < 2 3 4 5 6 >  Last ›