about summary refs log tree commit homepage
path: root/lib/unicorn.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-12-26 17:04:57 -0800
committerEric Wong <normalperson@yhbt.net>2009-12-26 17:15:11 -0800
commit5eea32764571b721cd1a89cf9ebfa853c621ac9e (patch)
tree7aae0814fe23d06945b92ee9158b3f02bbd37b4b /lib/unicorn.rb
parent643994afcdbd4121c0d131a87052cdd17d40e54f (diff)
downloadunicorn-5eea32764571b721cd1a89cf9ebfa853c621ac9e.tar.gz
This behavior change also means our grandparent (launched
from a controlling terminal or script) will wait until
the master process is ready before returning.

Thanks to IƱaki Baz Castillo for the initial implementations
and inspiration.
Diffstat (limited to 'lib/unicorn.rb')
-rw-r--r--lib/unicorn.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 71d5994..ae05f03 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -25,7 +25,8 @@ module Unicorn
 
   class << self
     def run(app, options = {})
-      HttpServer.new(app, options).start.join
+      ready_pipe = options.delete(:ready_pipe)
+      HttpServer.new(app, options).start.join(ready_pipe)
     end
   end
 
@@ -313,7 +314,7 @@ module Unicorn
     # (or until a termination signal is sent).  This handles signals
     # one-at-a-time time and we'll happily drop signals in case somebody
     # is signalling us too often.
-    def join
+    def join(ready_pipe = nil)
       # this pipe is used to wake us up from select(2) in #join when signals
       # are trapped.  See trap_deferred
       init_self_pipe!
@@ -324,6 +325,10 @@ module Unicorn
       trap(:CHLD) { |sig_nr| awaken_master }
       proc_name 'master'
       logger.info "master process ready" # test_exec.rb relies on this message
+      if ready_pipe
+        ready_pipe.syswrite($$.to_s)
+        ready_pipe.close
+      end
       begin
         loop do
           reap_all_workers