I am aware of the command to start the sphinx daemon manually. I use a rake task: "rake thinking_sphinx:start" Is it possible to have it start whenever my rails application loads so I don't have to manually type in the command every time?
views:
1044answers:
6You should be able to test if it's running and launch it from within rails (using back-ticks or the %x{...}
notation.
Given that (as you said in the comments) it's a rake task you may want to do it like so instead of with back-ticks:
Rake::Task['thinking_sphinx:start'].invoke
Put the command to launch it in your config/initializers/custom.rb
I've had to do the same thing in my app, but with windows. In case you're in the same sticky mess, you'll find that your life will be much easier if you do something like:
if app_not_already_running
IO.popen("start app") do |fd|
end
end
I'm looking at old code and I don't remember if the do |fd| was really necessary. Give it a shot.
The reason the 'start' is important is to con windows into backgrounding the cursed thing. Yargh!
If you are deploying via capistrano (and you should be), simply add it as an after_deploy:
desc "Run this after every successful deployment"
task :after_deploy, :roles => :app do
run "#{current_path}/rake thinking_sphinx:start"
end
You can configure daemon_controller to do this: http://blog.phusion.nl/2008/08/25/daemon_controller-a-library-for-robust-daemon-management/
As mentioned above, create a file in config/initializers. For example, I created a file called initializers/start_thinking_sphinx.rb. And in the file I put
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
require "#{RAILS_ROOT}/vendor/plugins/thinking-sphinx/tasks/thinking_sphinx_tasks"
Rake::Task['thinking_sphinx:start'].invoke
This works if I then start the server with script/server. However does not work if I start with passenger :(