Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow for NODETACH option when running `rake ts:start`.

This is useful for people using something like `foreman`.
  • Loading branch information...
commit 5d9159c23ef1206d3956a720fae45e5075fb9ed7 1 parent 856c003
Aaron Gibralter authored September 06, 2011

Showing 1 changed file with 19 additions and 5 deletions. Show diff stats Hide diff stats

  1. 24  lib/thinking_sphinx/tasks.rb
24  lib/thinking_sphinx/tasks.rb
@@ -37,12 +37,26 @@
37 37
 
38 38
     Dir["#{config.searchd_file_path}/*.spl"].each { |file| File.delete(file) }
39 39
 
40  
-    config.controller.start
41  
-
42  
-    if sphinx_running?
43  
-      puts "Started successfully (pid #{sphinx_pid})."
  40
+    if ENV["NODETACH"] == "true"
  41
+      # https://gist.github.com/994070
  42
+      # Workaround to make Sphinx die nicely:
  43
+      #   - PTY.spawn invokes bash -c under the covers
  44
+      #   - Which turns SIGTERM into SIGHUP (not sure exactly why, can't seem to find a reason)
  45
+      #   - Which sphinx interprets as a reload instead of a quit
  46
+      #   - So, we need to remap HUP to KILL for the purposes of this script.
  47
+      unless pid = fork
  48
+        config.controller.start(:nodetach => true)
  49
+      end
  50
+      trap("SIGHUP") { Process.kill(:TERM, pid) }
  51
+      Process.wait
44 52
     else
45  
-      puts "Failed to start searchd daemon. Check #{config.searchd_log_file}"
  53
+      config.controller.start
  54
+
  55
+      if sphinx_running?
  56
+        puts "Started successfully (pid #{sphinx_pid})."
  57
+      else
  58
+        puts "Failed to start searchd daemon. Check #{config.searchd_log_file}"
  59
+      end
46 60
     end
47 61
   end
48 62
 

0 notes on commit 5d9159c

Please sign in to comment.
Something went wrong with that request. Please try again.