unicorn 0.95.1
[unicorn.git] / lib / unicorn / launcher.rb
blob1229b84ad16dfb611622fab32d318457e57c366a
1 # -*- encoding: binary -*-
3 $stdin.sync = $stdout.sync = $stderr.sync = true
4 $stdin.binmode
5 $stdout.binmode
6 $stderr.binmode
8 require 'unicorn'
10 class Unicorn::Launcher
12   # We don't do a lot of standard daemonization stuff:
13   #   * umask is whatever was set by the parent process at startup
14   #     and can be set in config.ru and config_file, so making it
15   #     0000 and potentially exposing sensitive log data can be bad
16   #     policy.
17   #   * don't bother to chdir("/") here since unicorn is designed to
18   #     run inside APP_ROOT.  Unicorn will also re-chdir() to
19   #     the directory it was started in when being re-executed
20   #     to pickup code changes if the original deployment directory
21   #     is a symlink or otherwise got replaced.
22   def self.daemonize!
23     $stdin.reopen("/dev/null")
25     # We only start a new process group if we're not being reexecuted
26     # and inheriting file descriptors from our parent
27     unless ENV['UNICORN_FD']
28       exit if fork
29       Process.setsid
30       exit if fork
32       # $stderr/$stderr can/will be redirected separately in the Unicorn config
33       Unicorn::Configurator::DEFAULTS[:stderr_path] = "/dev/null"
34       Unicorn::Configurator::DEFAULTS[:stdout_path] = "/dev/null"
35     end
36     $stdin.sync = $stdout.sync = $stderr.sync = true
37   end
39 end