diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-30 18:11:07 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-30 18:11:07 +0000 |
| commit | 84db91e7fcd2027431ad0a3d7177ac7c11a8d48e (patch) | |
| tree | 2acaab26fdc3a565ca04a9f92ef1d981b0a76974 | |
| parent | 12c122c882c6053f8b21714bb8c4c8bf8be699c9 (diff) | |
| download | puppet-84db91e7fcd2027431ad0a3d7177ac7c11a8d48e.tar.gz puppet-84db91e7fcd2027431ad0a3d7177ac7c11a8d48e.tar.xz puppet-84db91e7fcd2027431ad0a3d7177ac7c11a8d48e.zip | |
Fixing the docs a bit for the executables, adding a --daemonize option to puppetd and puppetmasterd so they can still be daemonized with debugging or verbosity enabled, and causing puppetd to fail to start if a PID file exists (and not setting a pid file if running with --onetime enabled).
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1149 980ebf18-57e1-0310-9a29-db15c13687c0
| -rwxr-xr-x | bin/puppetd | 91 | ||||
| -rwxr-xr-x | bin/puppetmasterd | 58 | ||||
| -rw-r--r-- | lib/puppet/client.rb | 1 | ||||
| -rwxr-xr-x | lib/puppet/daemon.rb | 38 |
4 files changed, 127 insertions, 61 deletions
diff --git a/bin/puppetd b/bin/puppetd index a2450af70..2b396fc1e 100755 --- a/bin/puppetd +++ b/bin/puppetd @@ -8,10 +8,10 @@ # # = Usage # -# puppetd [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] -# [-l|--logdest <syslog|<file>|console>] [--fqdn <host name>] -# [-o|--onetime] [-w|--waitforcert <seconds>] [-t|--test] -# [--disable] [--enable] [--listen] +# puppetd [-D|--daemonize] [-d|--debug] [--disable] [--enable] +# [-h|--help] [--fqdn <host name>] [--listen] +# [-l|--logdest syslog|<file>|console] [-o|--onetime] [-t|--test] +# [-V|--version] [-v|--verbose] [-w|--waitforcert <seconds>] # # = Description # @@ -26,9 +26,29 @@ # Once the client has a signed certificate, it will retrieve its configuration # and apply it. # -# The vast majority of options are shared between all Puppet executables and -# are documented completely at -# http://reductivelabs.com/projects/puppet/documentation. +# = Usage Notes +# +# +puppetd+ does its best to find a compromise between interactive use and +# daemon use. Run with no arguments and no configuration, it will go into the +# backgroun, attempt to get a signed certificate, and retrieve and apply its +# configuration every 30 minutes. +# +# Some flags are meant specifically for interactive use -- in particular, +# +test+ and +tag+ are useful. +test+ enables verobse logging, causes +# the daemon to stay in the foreground, exits if the server's configuration is +# invalid (this happens if, for instance, you've left a syntax error on the +# server), and exits after running the configuration once (rather than hanging +# around as a long-running process). +# +# +tag+ allows you to specify what portions of a configuration you want to apply. +# Puppet elements are tagged with all of the class or definition names that +# contain them, and you can use the +tag+ flag to specify one of these names, +# causing only configuration elements contained within that class or definition +# to be applied. This is very useful when you are testing new configurations -- +# for instance, if you are just starting to manage +ntpd+, you would put all of +# the new elements into an +ntpd+ class, and call puppet with +--tag ntpd+, +# which would only apply that small portion of the configuration during your +# testing, rather than applying the whole thing. # # = Options # @@ -36,7 +56,16 @@ # is also a valid long argument. For example, 'server' is a valid configuration # parameter, so you can specify '--server <servername>' as an argument. # -# See the configuration file for the full list of acceptable parameters. +# See the configuration file documentation at +# http://reductivelabs.com/projects/puppet/documentation/puppet-executable-reference +# for the full list of acceptable parameters. +# +# daemonize:: +# Send the process into the background. This is the default unless +# +verbose+ or +debug+ is enabled. +# +# debug:: +# Enable full debugging. # # disable:: # Disable working on the local system. This puts a lock file in place, @@ -50,9 +79,6 @@ # # +puppetd+ exits after executing this. # -# debug:: -# Enable full debugging. -# # enable:: # Enable working on the local system. This removes any lock file, causing # +puppetd+ to start managing the local system again (although it will continue @@ -65,15 +91,15 @@ # certificate purposes, but can be used to override the discovered hostname. # If you need to use this flag, it is generally an indication of a setup problem. # +# help:: +# Print this help message +# # listen:: # Start a local listening server. This allows you to remotely manage # puppet nodes over XMLRPC. The client will fail to start if the # authorization config file (defaults to /etc/puppetd/namespaceauth.conf) # does not exist. # -# help:: -# Print this help message -# # logdest:: # Where to send messages. Choose between syslog, the console, and a log file. # Defaults to sending messages to syslog, or the console if debugging or @@ -94,8 +120,11 @@ # Print the puppet version number and exit. # # waitforcert:: -# Have the process wait around, continuously retrying for the certificate -# each <argument> seconds. +# This option only matters for daemons that do not yet have certificates +# and it is enabled by default, with a value of 60 (seconds). This causes +# +puppetd+ to connect to the server every 60 seconds and ask it to sign a +# certificate request. This is useful for the initial setup of a puppet +# client. # # = Example # @@ -125,6 +154,7 @@ end options = [ [ "--centrallogging", GetoptLong::NO_ARGUMENT ], + [ "--daemonize", "-D", GetoptLong::NO_ARGUMENT ], [ "--disable", GetoptLong::NO_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], [ "--enable", GetoptLong::NO_ARGUMENT ], @@ -164,6 +194,8 @@ begin case opt # First check to see if the argument is a valid configuration parameter; # if so, set it. + when "--daemonize" + options[:daemonize] = true when "--disable" options[:disable] = true when "--enable" @@ -235,10 +267,14 @@ if Puppet[:config] and File.exists? Puppet[:config] Puppet.config.parse(Puppet[:config]) end -if Puppet::Log.level == :debug or Puppet::Log.level == :info - args[:Daemonize] = false -else - args[:Daemonize] = true +# Default to daemonizing, but if verbose or debug is specified, +# default to staying in the foreground. +unless options.include?(:daemonize) + if Puppet::Log.level == :debug or Puppet::Log.level == :info + options[:daemonize] = false + else + options[:daemonize] = true + end end unless options[:setdest] @@ -259,6 +295,10 @@ if options[:centrallogs] Puppet::Log.newdestination(logdest) end +if options[:onetime] + Puppet[:setpidfile] = false +end + # We need tomake the client either way, we just don't start it # if --no-client is set. client = Puppet::Client::MasterClient.new(args) @@ -326,7 +366,7 @@ if options[:listen] objects << server end -if args[:Daemonize] +if options[:daemonize] client.daemonize end @@ -375,7 +415,7 @@ else begin server.start rescue => detail - Puppet.err "Could not start puppetmaster: %s" % detail + Puppet.err "Could not start server: %s" % [detail] exit(1) end end @@ -383,7 +423,12 @@ else if options[:client] Puppet.notice "Starting Puppet client version %s" % [Puppet.version] - client.start + begin + client.start + rescue => detail + Puppet.err "Could not start client: %s" % [detail] + exit(1) + end end threads << Thread.new do diff --git a/bin/puppetmasterd b/bin/puppetmasterd index d05eb29af..82dd45b99 100755 --- a/bin/puppetmasterd +++ b/bin/puppetmasterd @@ -7,8 +7,9 @@ # # = Usage # -# puppetmasterd [-h|--help] [-d|--debug] [-v|--verbose] [-V|--version] -# [--noca] [--nobucket] +# puppetmasterd [-D|--daemonize] [-d|--debug] [-h|--help] +# [-l|--logdest <file>|console|syslog] [--noca] [--nobucket] [--nonodes] +# [-v|--verbose] [-V|--version] # # = Description # @@ -20,7 +21,13 @@ # is also a valid long argument. For example, 'ssldir' is a valid configuration # parameter, so you can specify '--ssldir <directory>' as an argument. # -# See the configuration file for the full list of acceptable parameters. +# See the configuration file documentation at +# http://reductivelabs.com/projects/puppet/documentation/puppet-executable-reference +# for the full list of acceptable parameters. +# +# daemonize:: +# Send the process into the background. This is the default unless +# +verbose+ or +debug+ is enabled. # # debug:: # Enable full debugging. Causes the daemon not to go into the background. @@ -42,6 +49,7 @@ # nonodes:: # Do not use individual node designations; each node will receive the result # of evaluating the entire configuration. +# # verbose:: # Enable verbosity. Causes the daemon not to go into the background. # @@ -66,6 +74,7 @@ require 'puppet' require 'puppet/server' options = [ + [ "--daemonize", "-D", GetoptLong::NO_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--logdest", "-l", GetoptLong::REQUIRED_ARGUMENT ], @@ -90,26 +99,23 @@ rescue LoadError $haveusage = false end -haveca = true master = {} ca = {} fs = {} bucket = {} args = {} -#user = Puppet[:user] -#group = Puppet[:group] -user = nil -group = nil - -havebucket = true -parseonly = false - -setdest = false +options = { + :haveca => true, + :havebucket => true, + :setdest => false +} begin result.each { |opt,arg| case opt + when "--daemonize" + options[:daemonize] = true when "--debug" Puppet::Log.level = :debug Puppet::Log.newdestination(:console) @@ -121,15 +127,15 @@ begin exit end when "--noca" - haveca = false + options[:haveca] = false when "--nobucket" - havebucket = false + options[:havebucket] = false when "--nonodes" master[:UseNodes] = false when "--logdest" begin Puppet::Log.newdestination(arg) - setdest = true + options[:setdest] = true rescue => detail $stderr.puts detail.to_s end @@ -164,10 +170,14 @@ Puppet.genmanifest require 'etc' -if Puppet::Log.level == :debug or Puppet::Log.level == :info or parseonly - args[:Daemonize] = false -else - args[:Daemonize] = true +# Default to daemonizing, but if verbose or debug is specified, +# default to staying in the foreground. +unless options.include?(:daemonize) + if Puppet::Log.level == :debug or Puppet::Log.level == :info + options[:daemonize] = false + else + options[:daemonize] = true + end end handlers = { @@ -176,15 +186,15 @@ handlers = { :Logger => {} } -unless setdest +unless options[:setdest] Puppet::Log.newdestination(:syslog) end -if haveca +if options[:haveca] handlers[:CA] = ca end -if havebucket +if options[:havebucket] handlers[:FileBucket] = bucket end @@ -224,7 +234,7 @@ if Puppet[:parseonly] exit(0) end -if args[:Daemonize] +if options[:daemonize] server.daemonize end diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index 495e190f9..0dd5221ed 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -144,6 +144,7 @@ module Puppet # Start listening for events. We're pretty much just listening for # timer events here. def start + super # Create our timer timer = EventLoop::Timer.new( :interval => Puppet[:runinterval], diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb index 4b9e1f6f0..f8d67db95 100755 --- a/lib/puppet/daemon.rb +++ b/lib/puppet/daemon.rb @@ -6,8 +6,11 @@ module Puppet # A module that handles operations common to all daemons. This is included # into the Server and Client base classes. module Daemon + Puppet.config.setdefaults(:puppet, :setpidfile => [true, + "Whether to store a PID file for the daemon."]) def daemonname - $0.sub(/.+#{File::SEPARATOR}/,'') + #$0.sub(/.+#{File::SEPARATOR}/,'') + Puppet.name end # The path to the pid file for this server @@ -22,7 +25,7 @@ module Puppet exit(0) end - setpidfile() + #setpidfile() # Get rid of console logging Puppet::Log.close(:console) @@ -36,9 +39,9 @@ module Puppet Puppet::Log.reopen rescue => detail File.open("/tmp/daemonout", "w") { |f| - f.puts "Could not start %s: %s" % [$0, detail] + f.puts "Could not start %s: %s" % [Puppet.name, detail] } - Puppet.err "Could not start %s: %s" % [$0, detail] + Puppet.err "Could not start %s: %s" % [Puppet.name, detail] exit(12) end end @@ -205,14 +208,16 @@ module Puppet def setpidfile Puppet.config.use(:puppet) @pidfile = self.pidfile - if FileTest.exists?(@pidfile) - Puppet.info "Deleting old pid file" - begin - File.unlink(@pidfile) - rescue Errno::EACCES - Puppet.err "Could not delete old PID file; cannot create new one" - return - end + if FileTest.exists?(@pidfile) and not defined? $setpidfile + raise Puppet::Error, "A PID file already exists for #{Puppet.name} +at #{@pidfile}. Not starting." + #Puppet.info "Deleting old pid file" + #begin + # File.unlink(@pidfile) + #rescue Errno::EACCES + # Puppet.err "Could not delete old PID file; cannot create new one" + # return + #end end #unless FileTest.exists?(Puppet[:rundir]) @@ -220,14 +225,14 @@ module Puppet # File.chmod(01777, Puppet[:rundir]) #end - Puppet.info "Setting pidfile to %s" % @pidfile + Puppet.info "Creating PID file to %s" % @pidfile begin File.open(@pidfile, "w") { |f| f.puts $$ } rescue => detail Puppet.err "Could not create PID file: %s" % detail exit(74) end - Puppet.info "pid file is %s" % @pidfile + $setpidfile = true end # Shut down our server @@ -247,6 +252,11 @@ module Puppet super end + + def start + setpidfile() + super + end end end |
