Skip to content

Instantly share code, notes, and snippets.

@madhums
Created August 22, 2011 07:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save madhums/1161840 to your computer and use it in GitHub Desktop.
Save madhums/1161840 to your computer and use it in GitHub Desktop.
foreman and thinking sphinx
sphinx: bundle exec rake thinking_sphinx:run_in_foreground RAILS_ENV=development --trace
# lib/tasks/thinking_sphinx.rake
namespace :thinking_sphinx do
task :run_in_foreground => [ 'ts:conf', 'ts:in' ] do
thinking_sphinx = 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 "#{thinking_sphinx.bin_path}#{thinking_sphinx.searchd_binary_name} --pidfile --config #{thinking_sphinx.config_file} --nodetach"
end
trap("SIGHUP") { Process.kill(:TERM, pid) }
Process.wait
end
end
@galetahub
Copy link

For thinking-sphinx 3.0 version:

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

    # 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 "#{controller.bin_path}#{controller.searchd_binary_name} --pidfile --config #{controller.path} --nodetach"
    end

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

@schlick
Copy link

schlick commented Jul 13, 2014

In case it's useful, I simply used in my Procfile:

sphinx: bundle exec rake ts:start NODETACH=true

@concept47
Copy link

Thank you @schlick ...very Awesome!!!

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