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. --- bin/unicorn | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'bin') diff --git a/bin/unicorn b/bin/unicorn index 1ea3d1f..18edf43 100755 --- a/bin/unicorn +++ b/bin/unicorn @@ -1,5 +1,5 @@ #!/home/ew/bin/ruby -STDIN.sync = STDOUT.sync = STDERR.sync = true +$stdin.sync = $stdout.sync = $stderr.sync = true require 'unicorn' # require this first to populate Unicorn::DEFAULT_START_CTX require 'rack' require 'optparse' @@ -123,7 +123,7 @@ app = case env when "development" lambda do || Rack::Builder.new do - use Rack::CommonLogger, STDERR + use Rack::CommonLogger, $stderr use Rack::ShowExceptions use Rack::Lint run inner_app.call @@ -132,7 +132,7 @@ when "development" when "deployment" lambda do || Rack::Builder.new do - use Rack::CommonLogger, STDERR + use Rack::CommonLogger, $stderr run inner_app.call end.to_app end @@ -156,19 +156,26 @@ end # only daemonize if we're not inheriting file descriptors from our parent if daemonize + + $stdin.reopen("/dev/null") unless ENV['UNICORN_FD'] exit if fork Process.setsid exit if fork end - Dir.chdir("/") # setting options[:directory] will override this later on - File.umask(0000) - STDIN.reopen("/dev/null") - - # we can redirect these again in the Unicorn {before,after}_fork hooks - STDOUT.reopen("/dev/null", "a") - STDERR.reopen("/dev/null", "a") + # We don't do a lot of standard daemonization stuff: + # * $stderr/$stderr can/will be redirected separately + # * umask is whatever was set by the parent process at startup + # and can be set in config.ru and config_file, so making it + # 0000 and potentially exposing sensitive log data can be bad + # policy. + # * Don't bother to chdir here since Unicorn is designed to + # run inside APP_ROOT (or whatever the "directory" directive + # specifies). Unicorn will also re-chdir() to 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. end Unicorn.run(app, options) -- cgit v1.2.3-24-ge0c7