From 302beb7158a7217a3c8e5499ef98b33c284b1dd8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 9 Feb 2009 21:17:02 -0800 Subject: daemonization by setting UNICORN_DAEMONIZE env 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). --- bin/unicorn | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'bin') 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 -- cgit v1.2.3-24-ge0c7