From f4cb8f36dfb2ae05d64ef609d03795537b0720fa Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 17 May 2009 23:22:44 -0500 Subject: Adding some usability bits to puppetqd There's better logging, and it's a bit more exception-friendly. Signed-off-by: Luke Kanies --- lib/puppet/application/puppetqd.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/application/puppetqd.rb b/lib/puppet/application/puppetqd.rb index a3a302e17..d5c0c7a45 100644 --- a/lib/puppet/application/puppetqd.rb +++ b/lib/puppet/application/puppetqd.rb @@ -3,8 +3,10 @@ require 'puppet/daemon' require 'puppet/application' require 'puppet/resource/catalog' require 'puppet/indirector/catalog/queue' +require 'puppet/util' Puppet::Application.new(:puppetqd) do + extend Puppet::Util should_parse_config attr_accessor :daemon @@ -12,10 +14,19 @@ Puppet::Application.new(:puppetqd) do preinit do @daemon = Puppet::Daemon.new @daemon.argv = ARGV.dup + Puppet::Util::Log.newdestination(:console) # Do an initial trap, so that cancels don't get a stack trace. + + # This exits with exit code 1 trap(:INT) do - $stderr.puts "Cancelling startup" + $stderr.puts "Caught SIGINT; shutting down" + exit(1) + end + + # This is a normal shutdown, so code 0 + trap(:TERM) do + $stderr.puts "Caught SIGTERM; shutting down" exit(0) end @@ -31,12 +42,19 @@ Puppet::Application.new(:puppetqd) do option("--verbose","-v") command(:main) do + Puppet.notice "Starting puppetqd %s" % Puppet.version Puppet::Resource::Catalog::Queue.subscribe do |catalog| # Once you have a Puppet::Resource::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) - Puppet.notice "Processing queued catalog for %s" % catalog.name - catalog.save + benchmark(:notice, "Processing queued catalog for %s" % catalog.name) do + begin + catalog.save + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err "Could not save queued catalog for %s: %s" % [catalog.name, detail] + end + end end Thread.list.each { |thread| thread.join } -- cgit