🚀 See the 2024 Ruby on Rails Community Survey results!
Article  |  Development

3 Useful Lessons from Installing Thinking Sphinx on Engine Yard

Reading time: ~ 2 minutes

3 Useful Lessons from Installing Thinking Sphinx on Engine Yard

Recently, I was tasked with installing Thinking Sphinx on Engine Yard. When we're dealing with multiple application servers and a utility instance that is dedicated to running Thinking Sphinx processes, troubleshooting where each process is running can get a little messy. One problem I quickly ran into? A serious shortage of in-depth and up to date documentation from Engine Yard.

So while it’s fresh in mind, I thought I’d share a few helpful tips on a successful Thinking Sphinx installation for a Ruby on Rails app with a dedicated utility instance.

1. Use a chef recipe AKA “cookbook”

To get things started on the right foot, you should use a “cookbook” from a library of Engine Yard chef recipes. This makes it pretty easy to install different services for your application. This Engine Yard guide is a good resource to get started - with some caveats.

Here are a few important things to note:

  • Make sure you’re using the right version of the Sphinx cookbook. The default Sphinx cookbook is for Rails 3 (or thinking-sphinx v.2). We were on a Rails 4 application (thinking-sphinx v.3+) so we definitely needed to use thinking-sphinx-3 instead.
  • For thinking-sphinx-3, you’ll want to change the ‘frequency’ integer. This will create a scheduled cronjob that will reindex periodically. The default is 15 minutes.

2. There's no need to setup a cronjob for your app

If you set up your cookbook correctly, there should be no need to add a cronjob to your application through the Engine Yard UI.

That should be taken care of automatically by your cookbook, and is the easiest way to ensure that it’ll run on your utility server – not your application servers.

Take a look at your searchd logs at this location to check that your app is reindexing periodically. /data/<appname>/current/log/production.searchd.log

3. thinking-sphinx.yml woes

From this point, you should be able to run all of your manual sphinx commands by sshing into your utility instance.

If you’re still running into issues with Sphinx not running correctly on your utility instance, check if you have your config/thinking-sphinx.yml committed to your git repo.

Your application instances will attempt to symlink to a shared/config directory where your thinking-sphinx.yml should live. If you have one committed to your config directory, it will take precedence over the one in the shared directory and will cause issues.

You have one of two options:

  1. Remove the thinking-sphinx.yml from your version control, and utilize your .gitignore to use it for your development environment.
  2. Create an after_deploy.rb hook that symlinks the thinking_sphinx.yml after deploy.

A symlink after deploy hook might look something like this:

run "ln -nfs #{shared_path}/config/thinking-sphinx.yml #{release_path}/config/thinking-sphinx.yml"

I found that option one worked better for our situation. But if you need to commit your thinking-sphinx.yml for some reason, option two will be the way to go.

Lastly, don’t be afraid to ask for help

If you get stuck, make sure to ask the Engine Yard developers for help! From my experience, they’re incredibly knowledgeable and responsive. They’re quick to point application developers like us in the right direction.


Still feeling stumped?

If all of this feels over your head and you're looking for a partner to help you install your Rails application up on a cloud platform like Engine Yard, we’d love to help. Click below to request a free development estimate and schedule a quick call with us to discuss your needs.

Have a project that needs help?