summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-12-29 12:44:20 -0800
committerEric Wong <normalperson@yhbt.net>2009-12-29 21:20:37 -0800
commit8268fea415a8c76da810f0a43e0bf63ac6c77238 (patch)
tree441b8b3753a0b2f0d37546962da23d323fb10192
parent4239f0618c8107545fd5babd256c89ffd82553bd (diff)
Rainbows! does not yet know about ready_pipe, and will probably
not know about it until Unicorn 0.97.0
-rw-r--r--lib/unicorn/launcher.rb61
1 files changed, 32 insertions, 29 deletions
diff --git a/lib/unicorn/launcher.rb b/lib/unicorn/launcher.rb
index 1871420..ccf9d8c 100644
--- a/lib/unicorn/launcher.rb
+++ b/lib/unicorn/launcher.rb
@@ -19,44 +19,47 @@ class Unicorn::Launcher
   #     the directory it was started in when being re-executed
   #     to pickup code changes if the original deployment directory
   #     is a symlink or otherwise got replaced.
-  def self.daemonize!(options = {})
+  def self.daemonize!(options = nil)
     $stdin.reopen("/dev/null")
     $stdin.sync = true # may not do anything...
 
     # We only start a new process group if we're not being reexecuted
     # and inheriting file descriptors from our parent
     unless ENV['UNICORN_FD']
-      # grandparent - reads pipe, exits when master is ready
-      #  \_ parent  - exits immediately ASAP
-      #      \_ unicorn master - writes to pipe when ready
-
-      rd, wr = IO.pipe
-      grandparent = $$
-      if fork
-        wr.close # grandparent does not write
-      else
-        rd.close # unicorn master does not read
-        Process.setsid
-        exit if fork # parent dies now
-      end
+      if options
+        # grandparent - reads pipe, exits when master is ready
+        #  \_ parent  - exits immediately ASAP
+        #      \_ unicorn master - writes to pipe when ready
 
-      if grandparent == $$
-        # this will block until HttpServer#join runs (or it dies)
-        master_pid = (rd.readpartial(16) rescue nil).to_i
-        unless master_pid > 1
-          warn "master failed to start, check stderr log for details"
-          exit!(1)
+        rd, wr = IO.pipe
+        grandparent = $$
+        if fork
+          wr.close # grandparent does not write
+        else
+          rd.close # unicorn master does not read
+          Process.setsid
+          exit if fork # parent dies now
         end
-        exit 0
-      else # unicorn master process
-        options[:ready_pipe] = wr
-        # $stderr/$stderr can/will be redirected separately in the
-        # Unicorn config
-        Unicorn::Configurator::DEFAULTS[:stderr_path] = "/dev/null"
-        Unicorn::Configurator::DEFAULTS[:stdout_path] = "/dev/null"
-
-        # returns so Unicorn.run can happen
+
+        if grandparent == $$
+          # this will block until HttpServer#join runs (or it dies)
+          master_pid = (rd.readpartial(16) rescue nil).to_i
+          unless master_pid > 1
+            warn "master failed to start, check stderr log for details"
+            exit!(1)
+          end
+          exit 0
+        else # unicorn master process
+          options[:ready_pipe] = wr
+        end
+      else # backwards compat
+        exit if fork
+        Process.setsid
+        exit if fork
       end
+      # $stderr/$stderr can/will be redirected separately in the Unicorn config
+      Unicorn::Configurator::DEFAULTS[:stderr_path] = "/dev/null"
+      Unicorn::Configurator::DEFAULTS[:stdout_path] = "/dev/null"
     end
   end