Module Puppet::Daemon
In: lib/puppet/daemon.rb

A module that handles operations common to all daemons. This is included into the Server and Client base classes.

Methods

Included Modules

Puppet::Util

Public Instance methods

Put the daemon into the background.

[Source]

    # File lib/puppet/daemon.rb, line 14
14:     def daemonize
15:         if pid = fork()
16:             Process.detach(pid)
17:             exit(0)
18:         end
19:         
20:         setpidfile()
21: 
22:         # Get rid of console logging
23:         Puppet::Util::Log.close(:console)
24: 
25:         Process.setsid
26:         Dir.chdir("/")
27:         begin
28:             $stdin.reopen "/dev/null"
29:             $stdout.reopen "/dev/null", "a"
30:             $stderr.reopen $stdout
31:             Puppet::Util::Log.reopen
32:         rescue => detail
33:             File.open("/tmp/daemonout", "w") { |f|
34:                 f.puts "Could not start %s: %s" % [Puppet[:name], detail]
35:             }
36:             Puppet.err "Could not start %s: %s" % [Puppet[:name], detail]
37:             exit(12)
38:         end
39:     end

[Source]

    # File lib/puppet/daemon.rb, line 9
 9:     def daemonname
10:         Puppet[:name]
11:     end

The path to the pid file for this server

[Source]

    # File lib/puppet/daemon.rb, line 42
42:     def pidfile
43:         if Puppet[:pidfile] != ""
44:             Puppet[:pidfile]
45:         else
46:             File.join(Puppet[:rundir], daemonname() + ".pid")
47:         end
48:     end

Remove the pid file

[Source]

    # File lib/puppet/daemon.rb, line 51
51:     def rmpidfile
52:         threadlock(:pidfile) do
53:             locker = Puppet::Util::Pidlock.new(pidfile)
54:             if locker.locked?
55:                 locker.unlock or Puppet.err "Could not remove PID file %s" % [pidfile]
56:             end
57:         end
58:     end

Create the pid file.

[Source]

    # File lib/puppet/daemon.rb, line 61
61:     def setpidfile
62:         threadlock(:pidfile) do
63:             unless Puppet::Util::Pidlock.new(pidfile).lock
64:                 Puppet.err("Could not create PID file: %s" % [pidfile])
65:                 exit(74)
66:             end
67:         end
68:     end

Shut down our server

[Source]

    # File lib/puppet/daemon.rb, line 71
71:     def shutdown
72:         # Remove our pid file
73:         rmpidfile()
74: 
75:         # And close all logs except the console.
76:         Puppet::Util::Log.destinations.reject { |d| d == :console }.each do |dest|
77:             Puppet::Util::Log.close(dest)
78:         end
79: 
80:         super
81:     end

[Validate]