diff options
Diffstat (limited to 'lib/puppet/agent')
-rw-r--r-- | lib/puppet/agent/downloader.rb | 79 | ||||
-rw-r--r-- | lib/puppet/agent/fact_handler.rb | 48 | ||||
-rw-r--r-- | lib/puppet/agent/locker.rb | 7 | ||||
-rw-r--r-- | lib/puppet/agent/plugin_handler.rb | 25 |
4 files changed, 6 insertions, 153 deletions
diff --git a/lib/puppet/agent/downloader.rb b/lib/puppet/agent/downloader.rb deleted file mode 100644 index edc5931c3..000000000 --- a/lib/puppet/agent/downloader.rb +++ /dev/null @@ -1,79 +0,0 @@ -require 'puppet/agent' -require 'puppet/resource/catalog' - -class Puppet::Agent::Downloader - attr_reader :name, :path, :source, :ignore - - # Determine the timeout value to use. - def self.timeout - timeout = Puppet[:configtimeout] - case timeout - when String: - if timeout =~ /^\d+$/ - timeout = Integer(timeout) - else - raise ArgumentError, "Configuration timeout must be an integer" - end - when Integer: # nothing - else - raise ArgumentError, "Configuration timeout must be an integer" - end - - return timeout - end - - # Evaluate our download, returning the list of changed values. - def evaluate - Puppet.info "Retrieving #{name}" - - files = [] - begin - Timeout.timeout(self.class.timeout) do - catalog.apply do |trans| - trans.changed?.find_all do |resource| - yield resource if block_given? - files << resource[:path] - end - end - end - rescue Puppet::Error, Timeout::Error => detail - puts detail.backtrace if Puppet[:debug] - Puppet.err "Could not retrieve #{name}: %s" % detail - end - - return files - end - - def initialize(name, path, source, ignore = nil) - @name, @path, @source, @ignore = name, path, source, ignore - end - - def catalog - catalog = Puppet::Resource::Catalog.new - catalog.add_resource(file) - catalog - end - - def file - args = default_arguments.merge(:path => path, :source => source) - args[:ignore] = ignore if ignore - Puppet::Type.type(:file).create(args) - end - - private - - def default_arguments - { - :path => path, - :recurse => true, - :source => source, - :tag => name, - :owner => Process.uid, - :group => Process.gid, - :purge => true, - :force => true, - :backup => false, - :noop => false - } - end -end diff --git a/lib/puppet/agent/fact_handler.rb b/lib/puppet/agent/fact_handler.rb deleted file mode 100644 index 266ae1815..000000000 --- a/lib/puppet/agent/fact_handler.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'puppet/indirector/facts/facter' - -# Break out the code related to facts. This module is -# just included into the agent, but having it here makes it -# easier to test. -module Puppet::Agent::FactHandler - def download_fact_plugins? - Puppet[:factsync] - end - - def upload_facts - # XXX down = Puppet[:downcasefacts] - - reload_facter() - - # This works because puppetd configures Facts to use 'facter' for - # finding facts and the 'rest' terminus for caching them. Thus, we'll - # compile them and then "cache" them on the server. - Puppet::Node::Facts.find(Puppet[:certname]) - end - - # Retrieve facts from the central server. - def download_fact_plugins - return unless download_fact_plugins? - - Puppet::Agent::Downloader.new("fact", Puppet[:factsource], Puppet[:factdest], Puppet[:factsignore]).evaluate - end - - # Clear out all of the loaded facts and reload them from disk. - # NOTE: This is clumsy and shouldn't be required for later (1.5.x) versions - # of Facter. - def reload_facter - Facter.clear - - # Reload everything. - if Facter.respond_to? :loadfacts - Facter.loadfacts - elsif Facter.respond_to? :load - Facter.load - else - Puppet.warning "You should upgrade your version of Facter to at least 1.3.8" - end - - # This loads all existing facts and any new ones. We have to remove and - # reload because there's no way to unload specific facts. - Puppet::Node::Facts::Facter.load_fact_plugins() - end -end diff --git a/lib/puppet/agent/locker.rb b/lib/puppet/agent/locker.rb index 03736b278..c24fdad64 100644 --- a/lib/puppet/agent/locker.rb +++ b/lib/puppet/agent/locker.rb @@ -30,9 +30,14 @@ module Puppet::Agent::Locker def lockfile unless defined?(@lockfile) - @lockfile = Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile]) + #@lockfile = Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile]) + @lockfile = Puppet::Util::Pidlock.new(lockfile_path) end @lockfile end + + def running? + lockfile.locked? + end end diff --git a/lib/puppet/agent/plugin_handler.rb b/lib/puppet/agent/plugin_handler.rb deleted file mode 100644 index 306b8b6df..000000000 --- a/lib/puppet/agent/plugin_handler.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Break out the code related to plugins. This module is -# just included into the agent, but having it here makes it -# easier to test. -module Puppet::Agent::PluginHandler - def download_plugins? - Puppet[:pluginsync] - end - - # Retrieve facts from the central server. - def download_plugins - return nil unless download_plugins? - Puppet::Agent::Downloader.new("plugin", Puppet[:pluginsource], Puppet[:plugindest], Puppet[:pluginsignore]).evaluate.each { |file| load_plugin(file) } - end - - def load_plugin(file) - return if FileTest.directory?(file) - - begin - Puppet.info "Loading downloaded plugin %s" % file - load file - rescue Exception => detail - Puppet.err "Could not load downloaded file %s: %s" % [file, detail] - end - end -end |