diff options
author | Luke Kanies <luke@madstop.com> | 2009-04-13 16:51:56 -0500 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-04-22 14:39:38 +1000 |
commit | 444ae9f8341348b0b8163788ada35892bc98f562 (patch) | |
tree | a1cd2bfe9408bf57615538ad777bb38642933e00 | |
parent | 22ae661263b9b42c3ad4d4d6dee3d3b1d1d2e25b (diff) | |
download | puppet-444ae9f8341348b0b8163788ada35892bc98f562.tar.gz |
Adding puppetqd executable.
This uses the backported Application class, with a couple
of backported monkey-patches so the class works as expected
but in 0.24.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | bin/puppetqd | 53 | ||||
-rw-r--r-- | lib/puppet/application/puppetqd.rb | 107 |
2 files changed, 160 insertions, 0 deletions
diff --git a/bin/puppetqd b/bin/puppetqd new file mode 100644 index 000000000..14a15b519 --- /dev/null +++ b/bin/puppetqd @@ -0,0 +1,53 @@ +#!/usr/bin/env ruby +# == Synopsis +# +# Retrieve serialized records from a queue and process them in order. +# +# = Usage +# +# puppetqd [-d|--debug] [-v|--verbose] +# +# = Description +# +# This is a simple application that just processes entities in a queue as they +# are recieved. +# +# = 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 documentation at +# http://reductivelabs.com/trac/puppet/wiki/ConfigurationReference for +# the full list of acceptable parameters. A commented list of all +# configuration options can also be generated by running puppetd with +# '--genconfig'. +# +# debug:: +# Enable full debugging. +# +# help:: +# Print this help message +# +# verbose:: +# Turn on verbose reporting. +# +# version:: +# Print the puppet version number and exit. +# +# = Example +# +# puppetqd +# +# = Author +# +# Luke Kanies +# +# = Copyright +# +# Copyright (c) 2009 Reductive Labs, LLC +# Licensed under the GNU Public License + +require 'puppet/application/puppetqd' +Puppet::Application[:puppetqd].run diff --git a/lib/puppet/application/puppetqd.rb b/lib/puppet/application/puppetqd.rb new file mode 100644 index 000000000..995668bec --- /dev/null +++ b/lib/puppet/application/puppetqd.rb @@ -0,0 +1,107 @@ +require 'puppet' +require 'puppet/application' +require 'puppet/node/catalog' +require 'puppet/indirector/catalog/queue' + + +# BACKPORT - this method should be removed when merged into master. +class Puppet::Util::Settings + # Generate the list of valid arguments, in a format that OptionParser can + # understand, and add them to the passed option list. + def optparse_addargs(options) + # Add all of the config parameters as valid options. + self.each { |name, element| + options << element.optparse_args + } + + return options + end +end + +# BACKPORT - this method should be removed when merged into master. +class Puppet::Util::Settings::CElement + # get the arguments in OptionParser format + def optparse_args + if short + ["--#{name}", "-#{short}", desc, :REQUIRED] + else + ["--#{name}", desc, :REQUIRED] + end + end +end + +Puppet::Application.new(:puppetqd) do + + should_parse_config + + preinit do + # Do an initial trap, so that cancels don't get a stack trace. + trap(:INT) do + $stderr.puts "Cancelling startup" + exit(0) + end + + { + :verbose => false, + :debug => false + }.each do |opt,val| + options[opt] = val + end + + @args = {} + end + + option("--debug","-d") + option("--verbose","-v") + + command(:main) do + Puppet::Node::Catalog::Queue.subscribe do |catalog| + # Once you have a Puppet::Node::Catalog instance, calling save() on it should suffice + # to put it through to the database via its active_record indirector (which is determined + # by the terminus_class = :active_record setting above) + catalog.save + end + end + + # This is the main application entry point. + # BACKPORT - this method should be removed when merged into master. + # This method had to be added because Puppet.settings.parse takes no + # arguments in master but requires an argument in 0.24.x. + def run + run_preinit + parse_options + Puppet.settings.parse(Puppet[:config]) if should_parse_config? + run_setup + run_command + end + + # Handle the logging settings. + def setup_logs + 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 + end + + setup do + unless Puppet.features.stomp? + raise ArgumentError, "Could not load 'stomp', which must be present for queueing to work" + end + + setup_logs + + if Puppet.settings.print_configs? + exit(Puppet.settings.print_configs ? 0 : 1) + end + + Puppet::Node::Catalog.terminus_class = :active_record + end +end |