16: def daemonize
17: if pid = fork
18: Process.detach(pid)
19: exit(0)
20: end
21:
22: create_pidfile
23:
24:
25: Puppet::Util::Log.close(:console)
26:
27: Process.setsid
28: Dir.chdir("/")
29: begin
30: $stdin.reopen "/dev/null"
31: $stdout.reopen "/dev/null", "a"
32: $stderr.reopen $stdout
33: Puppet::Util::Log.reopen
34: rescue => detail
35: Puppet.err "Could not start #{Puppet[:name]}: #{detail}"
36: Puppet::Util::secure_open("/tmp/daemonout", "w") { |f|
37: f.puts "Could not start #{Puppet[:name]}: #{detail}"
38: }
39: exit(12)
40: end
41: end