Skip to content

Commit

Permalink
Fix NODETACH signals logic.
Browse files Browse the repository at this point in the history
I had my signals crossed :). Incorrect use of wait.

I have something similar working now in my development environment and it
seems to work with foreman.
  • Loading branch information
agibralter committed Sep 7, 2011
1 parent 5d9159c commit 3d534b5
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/thinking_sphinx/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,12 @@
Dir["#{config.searchd_file_path}/*.spl"].each { |file| File.delete(file) }

if ENV["NODETACH"] == "true"
# https://gist.github.com/994070
# 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
config.controller.start(:nodetach => true)
end
trap("SIGHUP") { Process.kill(:TERM, pid) }
Process.wait
Signal.trap('TERM') { Process.kill(:QUIT, pid) }
Signal.trap('INT') { Process.kill(:QUIT, pid) }
Process.wait(pid)
else
config.controller.start

Expand Down

0 comments on commit 3d534b5

Please sign in to comment.