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
2013-06-19 16:16:15 -07:00

20 lines
521 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", "w+"
STDIN.reopen null
STDOUT.reopen null
STDERR.reopen null
end
0
end unless respond_to?(:daemon)
end