Sphinx, Chef and EY Cloud

I'm getting a client up and running on EngineYard's Cloud offering, and it has been a pleasure. One of the things I've appreciated about using it is that I'm forced (in a good way) to use Chef, which is awesome.

Today I was ready to deploy a new version of the app with search using Sphinx, so I added the thinking_sphinx recipe to the default recipes that EngineYard provides, deployed my recipes, and I was done. Well, almost. This app also needs a regular update to the sphinx index, so I need a cron job to run the indexer.

After a quick scan of the Chef docs regarding cron, I added this snippet to my copy of the thinking_sphinx recipe:

cron "indexer" do minute "22" command "cd /data/#{app_name}/current && RAILS_ENV=#{node[:environment][:framework_env]} rake ts:index" user node[:owner_name] only_if do File.exist?("/var/log/engineyard/sphinx/#{app_name}") end end

After a simple deploy of the updated recipe, I now have a cron job that runs as my deploy user and runs the re-index rake task. Fun stuff.

P.S. Yes, I could have used EY's lovely web UI for adding the cron job rather than fiddling with the recipe, but I like having as much as possible living in text files under version control. :)