From 40fadd79cee6a26fc124ad42297754b88d5c59e5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 2 Mar 2009 19:27:44 -0800 Subject: Allow stderr_path and stdout_path to be set in the config As opposed to doing this in the shell, this allows the files to be reopened reliably after rotation. While we're at it, use $stderr/$stdout instead of STDERR/STDOUT since they seem to be more favored. --- lib/unicorn/configurator.rb | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'lib/unicorn/configurator.rb') diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb index 65b29c6..a51dcd3 100644 --- a/lib/unicorn/configurator.rb +++ b/lib/unicorn/configurator.rb @@ -4,7 +4,7 @@ module Unicorn class Configurator include ::Unicorn::SocketHelper - DEFAULT_LOGGER = Logger.new(STDERR) unless defined?(DEFAULT_LOGGER) + DEFAULT_LOGGER = Logger.new($stderr) unless defined?(DEFAULT_LOGGER) DEFAULTS = { :timeout => 60, @@ -24,6 +24,8 @@ module Unicorn :pid => nil, :backlog => 1024, :preload_app => false, + :stderr_path => nil, + :stdout_path => nil, } attr_reader :config_file @@ -130,14 +132,7 @@ module Unicorn end # sets the +path+ for the PID file of the unicorn master process - def pid(path) - if path - path = File.expand_path(path) - File.writable?(File.dirname(path)) or raise ArgumentError, - "directory for pid=#{path} not writable" - end - @set[:pid] = path - end + def pid(path); set_path(:pid, path); end def directory(path) @set[:directory] = path ? File.expand_path(path) : nil @@ -152,8 +147,29 @@ module Unicorn end end + def stderr_path(path) + set_path(:stderr_path, path) + end + + def stdout_path(path) + set_path(:stdout_path, path) + end + private + def set_path(var, path) #:nodoc: + case path + when NilClass + when String + path = File.expand_path(path) + File.writable?(File.dirname(path)) or \ + raise ArgumentError, "directory for #{var}=#{path} not writable" + else + raise ArgumentError + end + @set[var] = path + end + def set_hook(var, my_proc) #:nodoc: case my_proc when Proc -- cgit v1.2.3-24-ge0c7