1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/lib/puma/daemon_ext.rb
Evan Phoenix 4d77ce8347 Add options to daemonize puma
Previously I was opposed to these options because I felt like puma
should always be run under another monitoring process. But after doing
some thinking (and some deployment of puma) I realized that the daemon
option is simply too useful to not include.

I highly suggest it be used with -w, so that if a worker crashes the
whole server doesn't mysteriously disappear.
2012-09-25 09:34:10 -07:00

20 lines
515 B
Ruby

module Process
def self.daemon(nochdir=false, noclose=false)
exit if fork # Parent exits, child continues.
Process.setsid # Become session leader.
exit if fork # Zap session leader. See [1].
Dir.chdir "/" unless nochdir # Release old working directory.
if !noclose
null = File.open "/dev/null"
STDIN.reopen null
STDOUT.reopen null
STDERR.reopen null
end
0
end unless respond_to?(:daemon)
end