Skip to content

Instantly share code, notes, and snippets.

@jayzes
Created May 26, 2011 20:59
Show Gist options
  • Save jayzes/994070 to your computer and use it in GitHub Desktop.
Save jayzes/994070 to your computer and use it in GitHub Desktop.
Thinking Sphinx and Foreman
sphinx: bundle exec rake ts:run_in_foreground
namespace :ts do
task :run_in_foreground => [ 'ts:conf', 'ts:in' ] do
ts = ThinkingSphinx::Configuration.instance
# Workaround to make Sphinx die nicely:
# - PTY.spawn invokes bash -c under the covers
# - Which turns SIGTERM into SIGHUP (not sure exactly why, can't seem to find a reason)
# - Which sphinx interprets as a reload instead of a quit
# - So, we need to remap HUP to KILL for the purposes of this script.
unless pid = fork
exec "#{ts.bin_path}#{ts.searchd_binary_name} --pidfile --config #{ts.config_file} --nodetach"
end
trap("SIGHUP") { Process.kill(:TERM, pid) }
Process.wait
end
end
@klebervirgilio
Copy link

For new version..

namespace :ts do
  task :run_in_foreground => [ 'ts:configure', 'ts:index' ] do
    ts = ThinkingSphinx::Configuration.instance

    # Workaround to make Sphinx die nicely:
    #   - PTY.spawn invokes bash -c under the covers
    #   - Which turns SIGTERM into SIGHUP (not sure exactly why, can't seem to find a reason)
    #   - Which sphinx interprets as a reload instead of a quit
    #   - So, we need to remap HUP to KILL for the purposes of this script.

    unless pid = fork
      exec "#{ts.controller.bin_path}#{ts.controller.searchd_binary_name} --pidfile --config #{ts.configuration_file} --nodetach"
    end

    trap("SIGHUP") { Process.kill(:TERM, pid) }
    Process.wait

  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment