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