Sha256: 45805059258905ce11a4512282439650179110aa7b64b3d31f98a588cb3f0181

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

require 'puppet/agent'
require 'puppet/configurer'
require 'puppet/indirector'

# A basic class for running the agent.  Used by
# puppetrun to kick off agents remotely.
class Puppet::Agent::Runner
    extend Puppet::Indirector
    indirects :runner, :terminus_class => :rest

    attr_reader :status, :background, :options

    def agent
        Puppet::Agent.new(Puppet::Configurer)
    end

    def background?
        background
    end

    def initialize(options = {})
        if options.include?(:background)
            @background = options[:background]
            options.delete(:background)
        end

        valid_options = [:tags, :ignoreschedules]
        options.each do |key, value|
            raise ArgumentError, "Runner does not accept %s" % key unless valid_options.include?(key)
        end

        @options = options
    end

    def log_run
        msg = ""
        msg += "triggered run" %
        if options[:tags]
            msg += " with tags %s" % options[:tags]
        end

        if options[:ignoreschedules]
            msg += " ignoring schedules"
        end

        Puppet.notice msg
    end

    def run
        if agent.running?
            @status = "running"
            return
        end

        log_run()

        if background?
            Thread.new { agent.run(options) }
        else
            agent.run(options)
        end

        @status = "success"
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puppet-0.25.5 lib/puppet/agent/runner.rb
puppet-0.25.4 lib/puppet/agent/runner.rb
puppet-0.25.3 lib/puppet/agent/runner.rb
puppet-0.25.2 lib/puppet/agent/runner.rb
puppet-0.25.1 lib/puppet/agent/runner.rb
puppet-0.25.0 lib/puppet/agent/runner.rb