diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-02-09 21:17:02 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-02-09 21:17:02 -0800 |
commit | 302beb7158a7217a3c8e5499ef98b33c284b1dd8 (patch) | |
tree | cc63826a6a870eec4b4d80e91feef3d5c51c49b5 /bin | |
parent | 4b5e01a32cb005dd890c32a78cf34150efc7a208 (diff) | |
download | unicorn-302beb7158a7217a3c8e5499ef98b33c284b1dd8.tar.gz |
Daemonization only happens once at initial startup and is less intrusive than traditional daemonize routines: we do not chdir, set umask, or redirect/close STDOUT/STDERR since those are doable via other config options with Unicorn (and the Unicorn "config file" is just Ruby). STDIN has no business being open on a daemon (and can be dangerous to close if using certain buggy third-party libs).
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/unicorn | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/bin/unicorn b/bin/unicorn index a4c3f19..93441ae 100755 --- a/bin/unicorn +++ b/bin/unicorn @@ -13,5 +13,15 @@ else config = eval(File.read(ARGV[0])) config.kind_of?(Hash) or abort "config is not a hash: #{config.class}" app = config.delete(:app) or abort "Missing :app key in config!" + + # only daemonize if we're not inheriting file descriptors from our parent + if ENV['UNICORN_DAEMONIZE'] && ! ENV['UNICORN_FD'] + # don't set umask(0000), chdir("/") or redirect STDOUT/STDERR since + # it's more flexible to handle that in the config (which is just Ruby) + exit if fork + Process.setsid + exit if fork + STDIN.reopen("/dev/null") + end Unicorn.run(app, config) end |