daemon_controller + Thinking Sphinx
I’ve created simple rails initiator in order to start Sphinx through daemon_controller based on the Thinking Sphinx configuration. I hope it will help somebody.
require 'daemon_controller' def before_start if not ThinkingSphinx.define_indexes? config = ThinkingSphinx::Configuration.instance cmd = "#{config.bin_path}#{config.indexer_binary_name} --config \"#{config.config_file}\" --all" cmd << " --rotate" if ThinkingSphinx.sphinx_running? system cmd end end if defined?(ThinkingSphinx) if not ThinkingSphinx.sphinx_running? conf_instance = ThinkingSphinx::Configuration.instance @controller = DaemonController.new( :identifier => 'Sphinx search server', :start_command => "#{conf_instance.bin_path}#{conf_instance.searchd_binary_name} --pidfile --config \"#{conf_instance.config_file}\"", :before_start => method(:before_start), :ping_command => lambda { TCPSocket.new(conf_instance.configuration.searchd.address, conf_instance.configuration.searchd.port) }, :pid_file => conf_instance.configuration.searchd.pid_file, :log_file => conf_instance.configuration.searchd.log) @controller.start end end
Hi,
thanks for the code. I love it. Much better than those examples from Phusion as you utilize the configuration object. Keep it up and thanks again
Yves
1 Sep 09 at 5:11 pm
Hi Yves, thanks for your comment. I’m glad you found it useful.
Michał Kuklis
2 Sep 09 at 3:34 pm
Hi,
Thanks a lot for this piece of code Michal, I was dreading having to figure it out by myself
Jonathan
28 Sep 09 at 5:35 am