about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-03-02 18:48:47 -0800
committerEric Wong <normalperson@yhbt.net>2009-03-03 11:13:33 -0800
commit56aaf96ffccebf70bf98f41c64bf533cef68f802 (patch)
tree030620cf489aa64d1d3311112e3a9f76d63b5e28
parent5517fa27191228af9ef9ee2f4491398c73b505c1 (diff)
downloadunicorn-56aaf96ffccebf70bf98f41c64bf533cef68f802.tar.gz
This means processes will share less memory but things
should be compatible with all existing setups.
-rw-r--r--lib/unicorn.rb3
-rw-r--r--lib/unicorn/configurator.rb10
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 42ac8c0..998f8b8 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -89,7 +89,7 @@ module Unicorn
       config_listeners.each { |addr| listen(addr) }
       listen(Const::DEFAULT_LISTENER) if @listeners.empty?
       self.pid = @config[:pid]
-      build_app!
+      build_app! if @preload_app
       spawn_missing_workers
       self
     end
@@ -391,6 +391,7 @@ module Unicorn
     # traps for USR1, USR2, and HUP may be set in the @after_fork Proc
     # by the user.
     def init_worker_process(worker)
+      build_app! unless @preload_app
       TRAP_SIGS.each { |sig| trap(sig, 'IGNORE') }
       trap('CHLD', 'DEFAULT')
       trap('USR1') do
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index ebdcba6..65b29c6 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -23,6 +23,7 @@ module Unicorn
       :directory => nil,
       :pid => nil,
       :backlog => 1024,
+      :preload_app => false,
     }
 
     attr_reader :config_file
@@ -142,6 +143,15 @@ module Unicorn
       @set[:directory] = path ? File.expand_path(path) : nil
     end
 
+    def preload_app(bool)
+      case bool
+      when TrueClass, FalseClass
+        @set[:preload_app] = bool
+      else
+        raise ArgumentError, "preload_app=#{bool.inspect} not a boolean"
+      end
+    end
+
     private
 
     def set_hook(var, my_proc) #:nodoc: