diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-02-14 17:16:20 +0100 |
---|---|---|
committer | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-02-16 20:12:11 +0100 |
commit | 156fb81ca914f6d697dc2cb81788a1d9ab5a23e4 (patch) | |
tree | 40492c5e064eff8b140b2d33c70b7b86cb267f4c /bin | |
parent | 0c71c5cde211808ef6fd744ccbcc82b6cfc38bb5 (diff) | |
download | puppet-156fb81ca914f6d697dc2cb81788a1d9ab5a23e4.tar.gz puppet-156fb81ca914f6d697dc2cb81788a1d9ab5a23e4.tar.xz puppet-156fb81ca914f6d697dc2cb81788a1d9ab5a23e4.zip |
Move puppetd to the Application Controller paradigm
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/puppetd | 272 |
1 files changed, 2 insertions, 270 deletions
diff --git a/bin/puppetd b/bin/puppetd index 4c7f1d131..c4c106c6d 100755 --- a/bin/puppetd +++ b/bin/puppetd @@ -155,273 +155,5 @@ # Copyright (c) 2005, 2006 Reductive Labs, LLC # Licensed under the GNU Public License -# Do an initial trap, so that cancels don't get a stack trace. -trap(:INT) do - $stderr.puts "Cancelling startup" - exit(0) -end - -require 'puppet' -require 'puppet/agent' -require 'puppet/daemon' -require 'puppet/configurer' -require 'getoptlong' - -# Create this now, so it has access to ARGV -daemon = Puppet::Daemon.new -daemon.argv = ARGV.dup - -options = [ - [ "--centrallogging", GetoptLong::NO_ARGUMENT ], - [ "--disable", GetoptLong::NO_ARGUMENT ], - [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], - [ "--enable", GetoptLong::NO_ARGUMENT ], - [ "--fqdn", "-f", GetoptLong::REQUIRED_ARGUMENT ], - [ "--help", "-h", GetoptLong::NO_ARGUMENT ], - [ "--logdest", "-l", GetoptLong::REQUIRED_ARGUMENT ], - [ "--onetime", "-o", GetoptLong::NO_ARGUMENT ], - [ "--test", "-t", GetoptLong::NO_ARGUMENT ], - [ "--serve", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--no-client", GetoptLong::NO_ARGUMENT ], - [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], - [ "--version", "-V", GetoptLong::NO_ARGUMENT ], - [ "--waitforcert", "-w", GetoptLong::REQUIRED_ARGUMENT ] -] - -# Add all of the config parameters as valid options. -Puppet.settings.addargs(options) - -result = GetoptLong.new(*options) - -args = {} - -options = { - :waitforcert => 120, # Default to checking for certs every 5 minutes - :onetime => false, - :verbose => false, - :debug => false, - :centrallogs => false, - :setdest => false, - :enable => false, - :disable => false, - :client => true, - :fqdn => nil, - :serve => {} -} - -begin - explicit_waitforcert = false - result.each { |opt,arg| - case opt - # First check to see if the argument is a valid configuration parameter; - # if so, set it. NOTE: there is a catch-all at the bottom for defaults.rb - when "--disable" - options[:disable] = true - when "--serve" - if Puppet::Network::Handler.handler(arg) - options[:serve] << arg.to_sym - else - raise "Could not find handler for %s" % arg - end - when "--enable" - options[:enable] = true - when "--test" - options[:test] = true - when "--centrallogging" - options[:centrallogs] = true - when "--help" - if Puppet.features.usage? - RDoc::usage && exit - else - puts "No help available unless you have RDoc::usage installed" - exit - end - when "--version" - puts "%s" % Puppet.version - exit - when "--verbose" - options[:verbose] = true - when "--debug" - options[:debug] = true - when "--fqdn" - options[:fqdn] = arg - when "--no-client" - options[:client] = false - when "--onetime" - options[:onetime] = true - options[:waitforcert] = 0 unless explicit_waitforcert - when "--port" - args[:Port] = arg - when "--logdest" - begin - Puppet::Util::Log.newdestination(arg) - options[:setdest] = true - rescue => detail - if Puppet[:debug] - puts detail.backtrace - end - $stderr.puts detail.to_s - end - when "--waitforcert" - options[:waitforcert] = arg.to_i - explicit_waitforcert = true - else - Puppet.settings.handlearg(opt, arg) - end - } -rescue GetoptLong::InvalidOption => detail - $stderr.puts detail - $stderr.puts "Try '#{$0} --help'" - exit(1) -end - -# Now parse the config -Puppet.parse_config - -if options[:test] - # Enable all of the most common test options. - Puppet.settings.handlearg("--ignorecache") - Puppet.settings.handlearg("--no-usecacheonfailure") - Puppet.settings.handlearg("--no-splay") - Puppet.settings.handlearg("--show_diff") - Puppet.settings.handlearg("--no-daemonize") - options[:verbose] = true - options[:onetime] = true - options[:waitforcert] = 0 -end - -# Handle the logging settings. -if options[:debug] or options[:verbose] - Puppet::Util::Log.newdestination(:console) - if options[:debug] - Puppet::Util::Log.level = :debug - else - Puppet::Util::Log.level = :info - end -end - -unless options[:setdest] - Puppet::Util::Log.newdestination(:syslog) -end - -if Puppet.settings.print_configs? - exit(Puppet.settings.print_configs ? 0 : 1) -end - -# If noop is set, then also enable diffs -if Puppet[:noop] - Puppet[:show_diff] = true -end - -args[:Server] = Puppet[:server] -if options[:fqdn] - args[:FQDN] = options[:fqdn] - Puppet[:certname] = options[:fqdn] -end - -if options[:centrallogs] - logdest = args[:Server] - - if args.include?(:Port) - logdest += ":" + args[:Port] - end - Puppet::Util::Log.newdestination(logdest) -end - -# We need to specify a ca location for things to work, but -# until the REST cert transfers are working, it needs to -# be local. -Puppet::SSL::Host.ca_location = :remote - -Puppet::Transaction::Report.terminus_class = :rest - -Puppet::Resource::Catalog.terminus_class = :rest -Puppet::Resource::Catalog.cache_class = :yaml - -Puppet::Node::Facts.terminus_class = :facter -Puppet::Node::Facts.cache_class = :rest - -# We need tomake the client either way, we just don't start it -# if --no-client is set. -agent = Puppet::Agent.new(Puppet::Configurer) -if options[:enable] - agent.enable -elsif options[:disable] - agent.disable -end - -if options[:enable] or options[:disable] - exit(0) -end - -daemon.agent = agent - -server = nil - -# It'd be nice to daemonize later, but we have to daemonize before the -# waitforcert happens. -if Puppet[:daemonize] - daemon.daemonize -end - -host = Puppet::SSL::Host.new -cert = host.wait_for_cert(options[:waitforcert]) - -objects = [] - -# This has to go after the certs are dealt with. -if Puppet[:listen] and ! options[:onetime] - unless FileTest.exists?(Puppet[:authconfig]) - Puppet.err "Will not start without authorization file %s" % - Puppet[:authconfig] - exit(14) - end - - # FIXME: we should really figure out how to distribute the CRL - # to clients. In the meantime, we just disable CRL checking if - # the CRL file doesn't exist - unless File::exist?(Puppet[:cacrl]) - Puppet[:cacrl] = 'false' - end - - handlers = nil - - if options[:serve].empty? - handlers = [:Runner] - else - handlers = options[:serve] - end - - require 'puppet/network/server' - # No REST handlers yet. - server = Puppet::Network::Server.new(:handlers => [:facts], :xmlrpc_handlers => handlers, :port => Puppet[:puppetport]) - - daemon.server = server -elsif options[:onetime] and Puppet[:listen] - Puppet.notice "Ignoring --listen on onetime run" -end - -# If --onetime is specified, we don't run 'start', which means we don't -# create a pidfile. -if options[:onetime] - unless options[:client] - $stderr.puts "onetime is specified but there is no client" - exit(43) - end - - daemon.set_signal_traps - - begin - agent.run - rescue => detail - if Puppet[:trace] - puts detail.backtrace - end - Puppet.err detail.to_s - end - exit(0) -else - Puppet.notice "Starting Puppet client version %s" % [Puppet.version] - - daemon.start -end +require 'puppet/application/puppetd' +Puppet::Application[:puppetd].run |