MyFunnyDev

web, coding and beyond

daemon_controller + Thinking Sphinx

with 3 comments

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

Written by Michał Kuklis

July 22nd, 2009 at 2:13 am

Posted in Uncategorized

Tagged with ,

3 Responses to 'daemon_controller + Thinking Sphinx'

Subscribe to comments with RSS or TrackBack to 'daemon_controller + Thinking Sphinx'.

  1. 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

  2. Hi Yves, thanks for your comment. I’m glad you found it useful.

    Michał Kuklis

    2 Sep 09 at 3:34 pm

  3. 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

Leave a Reply