about summary refs log tree commit homepage
path: root/bin
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-03-02 19:27:44 -0800
committerEric Wong <normalperson@yhbt.net>2009-03-03 11:14:59 -0800
commit40fadd79cee6a26fc124ad42297754b88d5c59e5 (patch)
tree3295854c96266b7a24cb5d64a59ce52071121e13 /bin
parent56aaf96ffccebf70bf98f41c64bf533cef68f802 (diff)
downloadunicorn-40fadd79cee6a26fc124ad42297754b88d5c59e5.tar.gz
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.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/unicorn27
1 files changed, 17 insertions, 10 deletions
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)