Object
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.
# File lib/unicorn/launcher.rb, line 22
22: def self.daemonize!(options = nil)
23: $stdin.reopen("/dev/null")
24:
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: if options
29: # grandparent - reads pipe, exits when master is ready
30: # \_ parent - exits immediately ASAP
31: # \_ unicorn master - writes to pipe when ready
32:
33: rd, wr = IO.pipe
34: grandparent = $$
35: if fork
36: wr.close # grandparent does not write
37: else
38: rd.close # unicorn master does not read
39: Process.setsid
40: exit if fork # parent dies now
41: end
42:
43: if grandparent == $$
44: # this will block until HttpServer#join runs (or it dies)
45: master_pid = (rd.readpartial(16) rescue nil).to_i
46: unless master_pid > 1
47: warn "master failed to start, check stderr log for details"
48: exit!(1)
49: end
50: exit 0
51: else # unicorn master process
52: options[:ready_pipe] = wr
53: end
54: else # backwards compat
55: exit if fork
56: Process.setsid
57: exit if fork
58: end
59: # $stderr/$stderr can/will be redirected separately in the Unicorn config
60: Unicorn::Configurator::DEFAULTS[:stderr_path] = "/dev/null"
61: Unicorn::Configurator::DEFAULTS[:stdout_path] = "/dev/null"
62: end
63: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.