# File lib/daemon/Daemon.rb, line 26 26: def start 27: return unless @daemonize 28: 29: # Fork and have the parent exit 30: if (pid = fork) == 1 31: @log.fatal('First fork failed') 32: elsif !pid.nil? 33: # This is the parent. We can exit now. 34: @log.debug("Forked a child process with PID #{pid}") 35: exit 0 36: end 37: 38: # Create a new session 39: Process.setsid 40: # Fork again to make sure we lose the controlling terminal 41: if (pid = fork) == 1 42: @log.fatal('Second fork failed') 43: elsif !pid.nil? 44: # This is the parent. We can exit now. 45: @log.debug("Forked a child process with PID #{pid}") 46: exit 0 47: end 48: 49: @pid = Process.pid 50: 51: # Change current working directory to the file system root 52: Dir.chdir '/' 53: # Make sure we can create files with any permission 54: File.umask 0 55: 56: # We no longer have a controlling terminal, so these are useless. 57: $stdin.reopen('/dev/null') 58: $stdout.reopen('/dev/null', 'a') 59: $stderr.reopen($stdout) 60: 61: @log.info("The process is running as daemon now with PID #{@pid}") 62: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.