about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-27 13:51:12 -0700
committerEric Wong <normalperson@yhbt.net>2010-10-27 14:06:44 -0700
commit51b2b90284000aee8d79b37a5406173c45ae212d (patch)
tree9f1405b3cb04ba791b86b067a850668989942bc3 /lib
parentf62c5850d7d17d7b5e301a494f8bdf5be3674411 (diff)
downloadunicorn-51b2b90284000aee8d79b37a5406173c45ae212d.tar.gz
If a configuration directive is set at startup and later
unset, it correctly restores the original default value
as if it had never been set in the first place.

This applies to the majority of the configuration values with
a few exceptions:

* This only applies to stderr_path and stdout_path when
  daemonized (the usual case, they'll be redirected to
  "/dev/null").  When NOT daemonized, we cannot easily redirect
  back to the original stdout/stderr destinations.

* Unsetting working_directory does not restore the
  original working directory where Unicorn was started.
  As far as we can tell unsetting this after setting it is
  rarely desirable and greatly increases the probability of
  user error.
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn/configurator.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 9355c66..dd515a7 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -44,21 +44,24 @@ class Unicorn::Configurator
 
   def initialize(defaults = {}) #:nodoc:
     self.set = Hash.new(:unset)
-    use_defaults = defaults.delete(:use_defaults)
+    @use_defaults = defaults.delete(:use_defaults)
     self.config_file = defaults.delete(:config_file)
 
     # after_reload is only used by unicorn_rails, unsupported otherwise
     self.after_reload = defaults.delete(:after_reload)
 
-    set.merge!(DEFAULTS) if use_defaults
+    set.merge!(DEFAULTS) if @use_defaults
     defaults.each { |key, value| self.__send__(key, value) }
     Hash === set[:listener_opts] or
         set[:listener_opts] = Hash.new { |hash,key| hash[key] = {} }
     Array === set[:listeners] or set[:listeners] = []
-    reload
+    reload(false)
   end
 
-  def reload #:nodoc:
+  def reload(merge_defaults = true) #:nodoc:
+    if merge_defaults && @use_defaults
+      set.merge!(DEFAULTS) if @use_defaults
+    end
     instance_eval(File.read(config_file), config_file) if config_file
 
     parse_rackup_file
@@ -403,7 +406,10 @@ class Unicorn::Configurator
 
   # sets the working directory for Unicorn.  This ensures SIGUSR2 will
   # start a new instance of Unicorn in this directory.  This may be
-  # a symlink, a common scenario for Capistrano users.
+  # a symlink, a common scenario for Capistrano users.  Unlike
+  # all other Unicorn configuration directives, this binds immediately
+  # for error checking and cannot be undone by unsetting it in the
+  # configuration file and reloading.
   def working_directory(path)
     # just let chdir raise errors
     path = File.expand_path(path)