bin/puppetd in puppet-0.9.2 vs bin/puppetd in puppet-0.13.0

- old
+ new

@@ -7,14 +7,12 @@ # Currently must be run out periodically, using cron or something similar. # # = Usage # # puppetd [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] -# [--ssldir <cert directory>] [-l|--logdest <syslog|<file>|console>] -# [--fqdn <host name>] [-p|--port <port>] [-s|--server <server>] -# [-w|--waitforcert <seconds>] [-c|--confdir <configuration directory>] -# [--vardir <var directory>] [--centrallogging] +# [-l|--logdest <syslog|<file>|console>] [--fqdn <host name>] +# [-o|--onetime] [-w|--waitforcert <seconds>] [--centrallogging] # # = Description # # This is the main puppet client. Its job is to retrieve the local machine's # configuration from a remote server and apply it. In order to successfully @@ -27,18 +25,20 @@ # Once the client has a signed certificate, it will retrieve its configuration # and apply it. # # = Options # +# Note that any configuration parameter that's valid in the configuration file +# 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. +# # centrallogging:: # Send all produced logs to the central puppetmasterd system. This currently # results in a significant slowdown, so it is not recommended. # -# confdir:: -# The configuration root directory, where +puppetmasterd+ defaults to looking -# for all of its configuration files. Defaults to +/etc/puppet+. -# # debug:: # Enable full debugging. # # fqdn:: # Set the fully-qualified domain name of the client. This is only used for @@ -48,27 +48,17 @@ # help:: # Print this help message # # logdest:: # Where to send messages. Choose between syslog, the console, and a log file. -# Defaults to sending messages to /var/puppet/log/puppet.log, or the console -# if debugging or verbosity is enabled. +# Defaults to sending messages to syslog, or the console if debugging or +# verbosity is enabled. # -# port:: -# The port to which to connect on the remote server. Currently defaults to 8139. +# onetime:: +# Run the configuration once, rather than as a long-running daemon. This is +# useful for interactively running puppetd. # -# server:: -# The remote server from whom to receive the local configuration. Currently -# must also be the certificate authority. Currently defaults to 'puppet'. -# -# ssldir:: -# Where to store and find certificates. Defaults to /etc/puppet/ssl. -# -# vardir:: -# The variable-size directory, used for storing state. Defaults to -# /var/puppet. -# # verbose:: # Turn on verbose reporting. # # version:: # Print the puppet version number and exit. @@ -77,19 +67,19 @@ # Have the process wait around, continuously retrying for the certificate # each <argument> seconds. # # = Example # -# puppet -s puppet.domain.com +# puppetd --server puppet.domain.com # # = Author # # Luke Kanies # # = Copyright # -# Copyright (c) 2005 Reductive Labs, LLC +# Copyright (c) 2005, 2006 Reductive Labs, LLC # Licensed under the GNU Public License require 'puppet' require 'puppet/server' @@ -101,41 +91,46 @@ require 'rdoc/usage' rescue LoadError $haveusage = false end -result = GetoptLong.new( +options = [ [ "--centrallogging", GetoptLong::NO_ARGUMENT ], - [ "--confdir", "-c", GetoptLong::REQUIRED_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], [ "--fqdn", "-f", GetoptLong::REQUIRED_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--logdest", "-l", GetoptLong::REQUIRED_ARGUMENT ], - [ "--noop", "-n", GetoptLong::NO_ARGUMENT ], - [ "--port", "-p", GetoptLong::REQUIRED_ARGUMENT ], - [ "--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--ssldir", GetoptLong::REQUIRED_ARGUMENT ], + [ "--onetime", "-o", GetoptLong::NO_ARGUMENT ], [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], [ "--version", "-V", GetoptLong::NO_ARGUMENT ], - [ "--vardir", GetoptLong::REQUIRED_ARGUMENT ], [ "--waitforcert", "-w", GetoptLong::REQUIRED_ARGUMENT ] -) +] +# Add all of the config parameters as valid options. +Puppet.config.addargs(options) + +result = GetoptLong.new(*options) + server = "puppet" fqdn = nil args = {} waitforcert = false +onetime = false + centrallogs = false + +setdest = false + begin result.each { |opt,arg| case opt + # First check to see if the argument is a valid configuration parameter; + # if so, set it. when "--centrallogging" centrallogs = true - when "--confdir" - Puppet[:puppetconf] = arg when "--help" if $haveusage RDoc::usage && exit else puts "No help available unless you have RDoc::usage installed" @@ -143,73 +138,80 @@ end when "--version" puts "%s" % Puppet.version exit when "--verbose" - Puppet[:loglevel] = :info - Puppet[:logdest] = :console + Puppet::Log.level = :info + Puppet::Log.newdestination(:console) + setdest = true when "--debug" - Puppet[:loglevel] = :debug - Puppet[:logdest] = :console - when "--noop" - Puppet[:noop] = true - when "--ssldir" - Puppet[:ssldir] = arg + Puppet::Log.level = :debug + Puppet::Log.newdestination(:console) + setdest = true when "--fqdn" fqdn = arg - when "--server" - server = arg + when "--onetime" + onetime = true when "--port" args[:Port] = arg when "--logdest" begin - Puppet[:logdest] = arg + Puppet::Log.newdestination(arg) rescue => detail $stderr.puts detail.to_s end - when "--vardir" - Puppet[:puppetvar] = arg when "--waitforcert" - waitforcert = arg + waitforcert = arg.to_i + else + Puppet.config.handlearg(opt, arg) end } rescue GetoptLong::InvalidOption => detail + $stderr.puts detail $stderr.puts "Try '#{$0} --help'" - #$stderr.puts detail # FIXME RDoc::usage doesn't seem to work #if $haveusage # RDoc::usage(1,'usage') #end exit(1) end -bg = false +Puppet.genconfig +Puppet.genmanifest -if Puppet[:loglevel] == :debug or Puppet[:loglevel] == :info +# Now parse the config +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 end -args[:Server] = server +unless setdest + Puppet::Log.newdestination(:syslog) +end + +args[:Server] = Puppet[:server] if fqdn args[:FQDN] = fqdn end if centrallogs logdest = args[:Server] if args.include?(:Port) logdest += ":" + args[:Port] end - Puppet[:logdest] = logdest + Puppet::Log.newdestination(logdest) end - +Puppet.notice "Starting Puppet client version %s" % [Puppet.version] client = Puppet::Client::MasterClient.new(args) - unless client.readcert if waitforcert begin while ! client.requestcert do Puppet.notice "Did not receive certificate" @@ -223,24 +225,44 @@ unless client.requestcert Puppet.notice "No certificates; exiting" exit(1) end end + + # Now, because the Net::HTTP object cannot be modified once we've connected, + # we need to recreate the client with the certs intact + client = Puppet::Client::MasterClient.new(args) + unless client.readcert + PUppet.err "Could not read certificates after retrieving them" + exit(34) + end end -if bg +if args[:Daemonize] + #exit(13) client.daemonize end # now set up the network client with the certs, now that we have them client.setcerts -# and then retrieve and apply our configuration -begin - client.getconfig - client.apply -rescue => detail - Puppet.err detail.to_s - exit(13) +trap(:INT) { + client.shutdown +} + +if onetime + begin + client.run + rescue => detail + Puppet.err detail.to_s + if Puppet[:debug] + puts detail.backtrace + end + end +else + client.start + + # Mmm, hackish + Puppet.start end -# $Id: puppetd 733 2005-10-28 21:28:59Z luke $ +# $Id: puppetd 873 2006-02-07 23:12:33Z luke $