unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob 5ebc271370305f567f3083e42570ddf72a3106f1 1226 bytes (raw)
$ git show v0.91.0:lib/unicorn/launcher.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
$stdin.sync = $stdout.sync = $stderr.sync = true
require 'unicorn'

class Unicorn::Launcher

  # We don't do a lot of standard daemonization stuff:
  #   * 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.  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.
  def self.daemonize!
    $stdin.reopen("/dev/null")

    # We only start a new process group if we're not being reexecuted
    # and inheriting file descriptors from our parent
    unless ENV['UNICORN_FD']
      exit if fork
      Process.setsid
      exit if fork

      # $stderr/$stderr can/will be redirected separately in the Unicorn config
      Unicorn::Configurator::DEFAULTS[:stderr_path] = "/dev/null"
      Unicorn::Configurator::DEFAULTS[:stdout_path] = "/dev/null"
    end
    $stdin.sync = $stdout.sync = $stderr.sync = true
  end

end

git clone https://yhbt.net/unicorn.git